I am working on a project in php.Now i want to send a mail to any e-mail id.

How can i send it?

Is there any mail API for PHP there or not?
because right now i am running project on localhost(for testing).After completion of it i will upload it to web hosting server.

So can i send a mail from localhost to any e-mail id usinh PHP?


Recommended Answers

All 5 Replies

Why not check this site out? http://www.w3schools.com/php/php_mail.asp

It all depends on what your project is exactly about. There's diferent ways of approaching this, but check the link I gave you, it should help you.

You can temporarily use a service provider such as GMail, Yahoo and Hotmail for testing your script, even locally.

I always use the PHPMailer class (It's active on 3 projects of mine) and it hasn't let me down once.


can i send mail without using PHPMailer class?

Is it possible to send mail through Socket in php?

If you have a working SMTP email server installed on your web-server then you can use a simple PHP function to send mail:

mail($to, $subject, $body, $headers);

Headers are optional, but if you want to use them you prepare the $headers variable like this:

$headers = "From: Example@Email.com \r\n";
$headers.= "CC: Exampl3@Email.com \r\n";

Each header needs to use both \r and \n to work correctly.

To prepare the body nicely you can prepare it like this before sending it:

$body = wordwrap($body, 70);

You can collect any or all of these variables through an HTTP interface so you could send an email anywhere with any subject, body, headers,...

It would use the configured SMTP server for your web-server and it would send it through port 25.

commented: thanks a lot... +4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.