How to Send Email from a PHP Script

Using php mail() function to send emails from php script.

Send Email from a PHP Script Example :

The first argument to this function is the recipient, the second specifies the message’s subject and the third one should contain the body. So to send a simple sample message, we could use:

$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("

Message successfully sent!

“);
} else {
echo(“

Message delivery failed…

“);
}
?>

Save this file as mail.php and browse from url http://yourdomain/mail.php

Leave a Reply

You must be logged in to post a comment.