A time ago wrote a blog: thinkphp Integration series of SMS Verification Code, order notification
Said this is a text message notification flooding of the era; most of the website's mailbox registration has been replaced by SMS registration;
But e-mails and text messages still have important meanings and advantages in some scenes.
1:0 cost, no charge for sending mail;
2: Rich content and large amount of mail can be lengthy;
3: Increase the number of visits, users can easily access the site through the link in the mail;
Well, come down here. Integrated messaging system for thinkphp;
Example Project: Http://git.oschina.net/shuaibai123/thinkphp-bjyadmin
One: Introduction of Phpmail
Copy two files from the sample project to your own project;
/thinkphp/library/org/nx/class.phpmailer.php;
/thinkphp/library/org/nx/class.smtp.php;
Do not download from the official website, because the download of Phpmail directly into the thinkphp is some pits will be error;
What is wrong with the specific report;
Two: Setting Configuration items
/application/common/conf/config.php
' Email_from_name ' = ' + ',//Sender ' email_smtp ' + ',//SMTP server ' Email_username ' =&G T ',//Account ' Email_password ' + ',//password
If you use 163 mailbox; there is a pit; the first is to turn on SMTP;
650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160522/1463915654317133.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>
650) this.width=650; "title=" Bai Jun Haruka Blog "src=" Http://baijunyao.com/Upload/image/ueditor/20160522/1463916516228840.jpg " alt= "Bai Jun Remote Blog" style= "border:0px;"/>
In the process of opening is to set an authorization password; open to finish; another pit will be dug up synchronously;
The Email_password in the configuration item refers to the password that is not a 163-mailbox login;
Otherwise, SMTP connect () failed;
Three: Send mail
/** * Send mail * @param string $address Email address sent to multiple addresses need to be written in array form * @param string $subject title * @param string $content Content * @return boolean Success */function Send_email ($address, $subject, $content) { $email _smtp=c (' email_smtp '); $email _username=c (' email_username '); $email _password=c (' Email_password '); $email _from_name=c (' email_from_name '); if (Empty ($email _smtp) | | empty ($email _username) | | empty ($email _password) | | empty ($email _from_name)) { return array ("error" =>1 , "Message" = "Mailbox Configuration Incomplete"); } require './thinkphp/library/ Org/nx/class.phpmailer.php '; require './thinkphp/library/org/nx/class.smtp.php '; $phpmailer =new \phpmailer (); // set Phpmailer to use an SMTP server to send email $phpmailer->issmtp (); // set to HTML format $phpmailer->ishtml (True); // set the character encoding of the message ' $phpmailer->charset= ' UTF-8 '; / / set the SMTP server. $phpmailer->host= $email _smtp; // set to "Require verification" $phpmailer->smtpauth=true; // Set user name $ Phpmailer->username= $email _username; // Set password $phpmailer- >password= $email _password; // to set the From field of the message header. $phpmailer->from= $email _username; // Set sender name $phpmailer->fromname= $email _from_name; // add a recipient address that can be used multiple times to add multiple recipients if (Is_array ($address)) { foreach ($address as $ADDRESSV) { $phpmailer->addaddress ($ADDRESSV); } }else{ $ Phpmailer->addaddress ($address); } // Set message headers $phpmailer->subject= $subject; // Set the message body $ phpmailer->body= Send mail $content; // . if (! $phpmailer->send ()) { $ phpmailererror= $phpmailer->errorinfo; return array (" Error "=>1," "message" = $phpmailererror); }elsE{ return array ("error" =>0); }}
Send mail Call function;
Send_email (' [email protected] ', ' mail header ', ' email content '), or//If the mass message is passed in an array $emails=array (' [email protected] ', ' [email protected] '); Send_email ($emails, ' mail header ', ' mail content ');
This article for Bai Jun Remote original article, reprinted without contact with me, but please specify from Bai Jun Remote blog http://baijunyao.com
Thinkphp Integration Series Phpmailer Bulk Email