How to use phpmailer to send email code via SMTP-PHP source code

Source: Internet
Author: User
Phpmailer is a PHP function package used to send emails through SMTP.

Its functions include:

* Specify multiple recipients, CC addresses, hidden addresses, and reply addresses when sending mail.
* Multiple email codes are supported, including 8bit, base64, binary, and quoted-printable.
*. Supports SMTP Authentication.
*. Support for redundant SMTP servers
*. Supports attachments and Html-format emails.
*. Customize the mail header
* Images can be embedded in emails.
* Flexible debugging
*. Compatible SMTP servers include Sendmail, qmail, Postfix, Imail, and Exchange.
*. Can run on any platform

Usage

Require ("class. phpmailer. php "); // This is an smtp php document. you can download $ mail = new PHPMailer () online (); // Create a mail sending class $ mail-> CharSet = "UTF-8"; $ address = "sdasdsadsa@qq.com"; $ mail-> IsSMTP (); // use SMTP to send $ mail-> Host = "smtp.126.com"; // your enterprise Post Office domain name $ mail-> SMTPAuth = true; // enable SMTP Authentication $ mail-> Username = "sffsdf@126.com"; // Post Office Username (enter the complete email address) $ mail-> Password = "123444 "; // Post Office password $ mail-> Port = 25; $ mail-> From = "sffsdf@126.com"; // mail Recipient email address $ mail-> FromName = "online Q & a"; $ mail-> AddAddress ("$ address", "a"); // recipient address, you can replace it with any email address in the format of AddAddress ("recipient email", "recipient name") // $ mail-> AddReplyTo ("",""); // $ mail-> AddAttachment ("/var/tmp/file.tar.gz"); // add an attachment $ mail-> IsHTML (true ); // set email format to HTML // whether to use the HTML format $ mail-> Subject = "online Q & "; // email Title $ mail-> Body = "Welcome to the online Q chat website"; // the email content. If HTML is set above, it can be HTMLif (! $ Mail-> Send () {echo "failed to Send the email.

"; Echo" error cause: ". $ mail-> ErrorInfo; exit ;}

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.