Php email sending method
First, download a phpmailer compressed package (you can find it in any search)
Decompress the package
The code is as follows:
Require ("phpmailer/class. phpmailer. php"); // introduce the file (put the files just extracted to the corresponding path)
$ Mail = new PHPMailer (); // instantiate
$ Mail-> IsSMTP (); // enable SMTP
$ Mail-> Host = "smtp.126.com"; // name of the smtp server (for example, email 126)
$ Mail-> SMTPAuth = true; // enable smtp Authentication
$ Mail-> Username = "****** @ 126.com"; // your mailbox name
$ Mail-> Password = "*****"; // email Password
$ Mail-> From = "***** @ 126.com"; // sender address (that is, your email address)
$ Mail-> FromName = "*****"; // sender's name
$ Mail-> AddAddress ("recipient address", "recipient name"); // add recipient
$ Mail-> AddReplyTo ("***** @ 126.com"," ***** "); // reply address (optional)
$ Mail-> WordWrap = 50; // you can specify the length of each line.
$ Mail-> AddAttachment ("images/01.jpg"," manu.jpg "); // add an attachment and specify a name
$ Mail-> IsHTML (true); // whether the email is in HTML format
$ Mail-> CharSet = "UTF-8"; // sets the email encoding.
$ Mail-> Subject = "*****"; // email Subject
$ Mail-> Body = "*******"; // mail content
$ Mail-> AltBody = "This is the body in plain text for non-HTML mail clients"; // the mail body does not support alternate HTML display.
If (! $ Mail-> Send ())
{
Echo "Message cocould not be sent.
";
Echo "Mailer Error:". $ mail-> ErrorInfo;
Exit ();
} Else {
Echo "Message has been sent ";
}
?>