mail("anyuserid@example.on.ca","My Subject","Line 1\n Line 2\n");
Return True on success and False on failure mail("nobody@example.com", "the subject", $message,
"From: webmaster@sitename\nReply-To: webmaster@sitename\nXMailer:
PHP/" . phpversion());
With the fifth parameter you can set additional command line parameters to the actual mailer. In the example below we set
the correct Return-Path header for sendmail. Normally sendmail will add the X-Authentication-Warning header when
using the -f parameter, because the webserver user is probably not a member of the trusted users. To suppress this warning,
you should add the web server user to the trusted users in your sendmail config file.
mail("nobody@aol.com", "the subject", $message,
"From: webmaster@$SERVER_NAME", "-fwebmaster@$SERVERNAME");
You can also use fairly simple string building techniques to build complex email messages.
Sending complex email.
/* recipients */
$recipient .= "friend_name <mary@sitename.com>" . ", " ; //note the comma
$recipient .= "next_friend <second@anothersite.com>" . ", ";
$recipient .= "onemore@greatsite.net";
/* subject */
$subject = "Checking PHP mail";
/* message */
$message .= "This is a test mail \n";
/* you can add a stock signature */
$message .= "-\r\n"; //Signature delimiter
/* additional header pieces for errors, From cc's, bcc's, etc */
$headers .= "From: The great webmaster \n";
$headers .= "To-Sender: <birthday@sitename.net>\n";
$headers .= "X-Mailer: PHP\n"; // mailer
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: <name@site.net> \n"; // Return path for errors
/* If you want to send html mail, uncomment the following line */
// $headers .= "Content-Type: text/html; charset=iso-8859-1 \n"; // Mime type
$headers .= "cc:userid_someone@sitename.net \n"; // CC to
$headers .= "bcc:userid_onemore@sitename.net, someone@example.com \n"; // BCCs to
/* and now mail it */
mail($recipient, $subject, $message, $headers);
PHP Mailer class
PHPMailer class using SMTP
Sending Multiple Mails
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| albert gerio | 28-04-2015 |
| hi friend can i get source code of this mail projects, thanks hugs :) | |
| smo1234 | 29-04-2015 |
| It is already there, copy it. | |