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 ' and ' = ',//Account
' Email_password ' and ' = ',//password
If you use 163 mailbox; there is a pit; the first is to turn on SMTP;
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 The email address that needs to be sent to multiple addresses needs to be written in an array form
* @param string $subject title
* @param string $content content
* @return Boolean is successful
*/
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 send email using an SMTP server
$phpmailer->issmtp ();
Set to HTML format
$phpmailer->ishtml (TRUE);
Set the character encoding of the message '
$phpmailer->charset= ' UTF-8 ';
Set up 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;
Sets 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 the message header
$phpmailer->subject= $subject;
Set the message body
$phpmailer->body= $content;
Send the message.
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 ');
If a 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