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...