PHP mail (126 mailbox and PHPMailer open source) I. first download PHPMailer
Https://github.com/chenlian2015/phpmailer.git
2. Download
Class. phpmailer. php
Class. smtp. php
Copy two files to your project directory.
III. use
CharSet = "GBK"; // Set the mail encoding, the default ISO-8859-1, this must be set if you send Chinese, otherwise garbled $ mail-> IsSMTP (); // Set the SMTP Service $ mail-> SMTPDebug = 1; // enable SMTP debugging // 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 = 'smtp .126.com '; // SMTP server $ mail-> Port = 25; // SMTP server Port $ mail-> Username = 'write your 126 mailbox here '; // SMTP server user name, PS: I am playing $ mail-> Password = 'here Write your password '; // SMTP server password $ mail-> SetFrom ('write your 126 mailbox here', 'who '); $ mail-> AddReplyTo ('write the destination email here ', 'name'); $ 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 ("windowsment"); // 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! ";}} Postmail ('write the target email here ', 'My subobject', 'Hang LA');?>