First, download the function package
Address: Https://github.com/PHPMailer/PHPMailer
Second, the test server environment
Use the Phpinfo () function to print out whether sockets is supported (the socket is part of the PHP extension), and if "enable" indicates environmental support.
Third, extract the extracted files
Unzip the downloaded Phpmailer-master.zip package and extract the following files
class.phpmailer.php
class.pop3.php
class.smtp.php
phpmailerautoload.php
Four, write Send mail demo, can be extracted as tool class
The detailed code is as follows:
Public functionSendMail () {require_once(Vendor_path. " Phpmailer/phpmailerautoload.php "); $mail=New\phpmailer;// Create a Phpmailer instance $mail->ISSMTP ();//send using SMTP mode $mail->charset = "UTF-8";// set encoding, otherwise send Chinese garbled $mail->host = "smtp.qq.com";// The host IP that needs to send mail, the following is the QQ host server $mail->smtpauth =true;//enable the SMTP authentication feature $mail->username = "[email protected]";// Sender Email Account $mail->password = "Xxxxxxxxxx";// Sender's mailbox password, QQ mailbox generated authorization code, QQ mailbox need to open IMAP/SMTP service $mail->setfrom (' [email protected] ', ' sender name ');// Set Sender information (parameter 1: Sender's mailbox, Parameter 2: Sender name) $mail->addaddress (' [email protected] ', ' Recipient name ');// Recipient Mailbox----Note If this is a mass, pity Dorado for loop add recipient mailbox $mail->subject = ' Sub-geumcheon ';// subject of the message, which is the title $mail->body = ' Green Anthony, leisurely I think, longitudinal I do not go, Zinning not come. Pick Xi da Xi, in the city Que Xi, a day, such as March XI. ‘;//Message Content $mail->altbody = ' message attachment information ';// message attachment information, can be omitted $mail-WordWrap= 50;// Line break, how many characters per line are wrapped automatically//$mail->ishtml (TRUE); Whether to send HTML if(!$mail->send ()) {// Send mail Echo"Mailer Error:".$mail-errorinfo; } Else { Echo"Sent successfully!"; }
It is recommended to send content in HTML format. You can use the <BR \> line break Note: If you are developing a mail message in text format, the "\ n", "\ r \ n" line breaks do not take effect, only the set wordwrap specifies the number of characters per line
Reprint please indicate source: Research and development, this article link: http://www.yanfadi.com/article/4.html
Phpmailer use Method (Support mass):