Use PHPMailer to send PHP emails # reprinted from: Cainiao on the cloud #, _ PHP Tutorial

Source: Internet
Author: User
Use PHPMailer to send PHP emails # reprinted from: Cainiao on the cloud #,. Use PHPMailer to send PHP emails # reprinted from: on the cloud #, and use PHPMailer to send PHP emails 1. first, download PHPMailercode. google. comaapac uses PHPMailer to send PHP emails # reposted from: Cainiao on the cloud #,
Use PHPMailer to send PHP emails

1. first download PHPMailer

Http://code.google.com/a/apache-extras.org/p/phpmailer/

2. extract

Take out class. phpmailer. php and class. smtp. php and put them in the folder of your project, because we will reference them later.

3. create the email sending function. you need to configure the smtp server.

Function postmail ($ to, $ subject = '', $ body ='') {// Author: Jiucool WebSite: http://www.jiucool.com // $ To indicates the recipient address $ subject indicates the Mail Title $ body indicates the mail body // error_reporting (E_ALL); error_reporting (E_STRICT); date_default_timezone_set ('Asia/Shanghai '); // Set require_once ('class. phpmailer. php '); include ('class. smtp. php '); $ mail = new PHPMailer (); // A new PHPMailer object comes out $ body = eregi_replace ("[\]", '', $ body ); // perform necessary filtering on the mail content $ mail-> CharSet = "GBK"; // Set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise, garbled code $ mail-> IsSMTP (); // you can specify the SMTP Service $ mail-> SMTPDebug = 1; // enable the SMTP debugging function // 1 = errors and messages // 2 = messages only $ mail-> SMTPAuth = true; // enable the SMTP authentication function $ mail-> SMTPSecure = "ssl"; // security protocol. you can comment out $ mail-> Host = 'stmp .163.com '; // SMTP server $ mail-> Port = 25; // SMTP server Port $ mail-> Username = 'hangzhou_198x'; // SMTP server user name, PS: I am hitting $ mail-> Password = 'password'; // SMTP server password $ mail-> SetFrom ('XXX @ xxx. xxx ', 'who'); $ mail-> AddReplyTo ('XXx @ xxx. xxx ', 'who'); $ mail-> Subject = $ subject; $ mail-> AltBody = 'To view the message, please use an HTML compatible email viewer! '; // Optional, comment out and test $ mail-> MsgHTML ($ body); $ address = $ to; $ mail-> AddAddress ($ address ,''); // $ mail-> AddAttachment ("images/phpmailer.gif"); // attachment // $ mail-> AddAttachment ("images/phpmailer_mini.gif"); // attachment if (! $ Mail-> Send () {echo 'mailer Error: '. $ mail-> ErrorInfo;} else {// echo "Message sent! Congratulations, the email is sent successfully! ";}}

4. use functions

Postmail ('wangliang _ 198x@163.com ', 'My subject', 'flushula LA ');

Pipeline to complete PHP mail sent # reprinted from: rookie in the cloud #, using PHPMailer to complete PHP mail sent 1. first download PHPMailer http://code.google.com/a/apac...

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.