Php email sending method

Source: Internet
Author: User
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 ";
}

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.