This article mainly introduces how thinkphp uses phpmailer to send mails, including configuring the mail class, setting parameters, and sending mail test steps, which has some practical value, for more information, see
This article mainly introduces how thinkphp uses phpmailer to send mails, including configuring the mail class, setting parameters, and sending mail test steps, which has some practical value, for more information, see
This example describes how thinkphp uses phpmailer to send emails. Share it with you for your reference. The specific analysis is as follows:
Phpmailer is the preferred email sending plug-in for php developers. Next I will introduce how to integrate phpmailer into the thinkphp framework. If you are interested, refer to it.
Phpmailer has a powerful email sending function. For a real experience today, I will briefly introduce the configuration, which I used in thinkphp.
Configuration steps:
1. Configure the mail sending class in the background at admin/common. php. The Code is as follows:
The Code is as follows:
Function sendmail ($ tomail, $ title, $ content)
{
/* Email setting information */
$ Email_set = C ('email _ set ');
Vendor ('phpmailer. class # phpmailer ');
Vendor ("phpmailer. class # smtp"); // optional; otherwise, it will include
$ Mail = new PHPMailer (true); // instantiate the PHPMailer class. true indicates that an exception is thrown when an error occurs.
$ Mail-> IsSMTP (); // use SMTP
$ Mail-> CharSet = "UTF-8"; // sets the email Encoding
$ Mail-> Host = $ email_set ['host']; // SMTP server
$ Mail-> SMTPDebug = 1; // enable SMTP debugging 1 = errors 2 = messages
$ Mail-> SMTPAuth = true; // The server must be verified.
$ Mail-> Port = $ email_set ['Port']; // set the port
// $ Mail-> SMTPSecure = "ssl ";
/*
$ Mail-> SMTPSecure = "ssl ";
$ Mail-> Host = "smtp.gmail.com ";
$ Mail-> Port = 465;
*/
$ Mail-> Username = $ email_set ['email _ user']; // user Account of the SMTP server
$ Mail-> Password = $ email_set ['email _ pwd']; // Password of the SMTP server
$ Mail-> AddReplyTo ($ email_set ['email '], $ email_set ['email _ name']); // The recipient replies to this email address when replying, this method can be executed multiple times.
If (is_array ($ tomail )){
Foreach ($ tomail as $ m ){
$ Mail-> AddAddress ($ m, 'user ');
}
} Else {
$ Mail-> AddAddress ($ tomail, 'user ');
}
$ Mail-> SetFrom ($ email_set ['email '], $ email_set ['email _ name']);
// $ Mail-> AddAttachment ('./img/phpmailer.gif'); // Add an attachment. If multiple attachments exist, repeat this method.
$ Mail-> Subject = $ title;
// The email content is as follows:
$ Mail-> Body = $ content;
$ Mail-> IsHTML (true );
// $ Body = file_get_contents('tpl.html '); // retrieves html webpage content
// $ Mail-> MsgHTML (eregi_replace ("[]", '', $ body ));
Return $ mail-> Send ()? True: false;
}
2: Configure parameters in the configuration file. The Code is as follows:
The Code is as follows: