This article mainly introduces the PHP mail sending function in detail. a PHPMailer plug-in can easily implement the Mail sending function, which has some reference value, interested friends can refer to this article for details about the PHP mail sending function. a PHPMailer plug-in can easily implement the Mail sending function, which has a certain reference value, for more information, see
The example in this article shares with you the code for sending the email ThinkPHP3.2.3 for your reference. The details are as follows:
First, Step 1: shut down a PHPMailer plug-in on the internet. after downloading and unzipping, we only need to use two of the files, as shown in:
/*** Function: email sending function * @ param string $ to target email * @ param string $ subject (title) * @ param string $ to mail content * @ return bool true */function sendMail ($ to, $ subject, $ content) {vendor ('phpmailer. class # smtp '); vendor ('phpmailer. class # phpmailer '); // note the case here. Otherwise, the class cannot be found. PHPMailer is the folder name, and class # phpmailer represents the class. phpmailer. php file name $ mail = new PHPMailer (); // assemble the email server if (C ('mail _ SMTP ') {$ MAIL-> IsSMTP ();} $ mail-> H Ost = C ('mail _ host'); // For Parameter explanations, see the following configuration information annotations $ MAIL-> SMTPAuth = C ('mail _ SMTPAUTH '); $ mail-> Username = C ('mail _ username'); $ MAIL-> Password = C ('mail _ password '); $ mail-> SMTPSecure = C ('mail _ SECURE '); $ MAIL-> CharSet = C ('mail _ charset '); // assemble the mail header information $ MAIL-> From = C ('mail _ username'); $ mail-> AddAddress ($ ); $ mail-> FromName = C ('mail _ fromname'); $ MAIL-> IsHTML (C ('mail _ ISHTML ')); // assemble the email body information $ mail-> Subject = $ Subject; $ mail-> Body = $ content; // send the email if (! $ Mail-> Send () {return FALSE;} else {return TRUE ;}}
3. the C method is used in the above functions to load some configuration information, so we have to go to the configuration file (default/Application/Home/Conf/config. php) add the following configuration information:
TRUE, 'mail _ host' => 'smtp .163.com ', // The smtp server 'mail _ SMTPAUTH' => TRUE, 'mail _ username' => '2017 *** @ 163.com ', // SMTP server login USERNAME 'mail _ password' => '123456abc ', // SMTP server login password 'mail _ SECURE '=> 'tls', 'mail _ charset' => 'utf-8', 'mail _ ISHTML '=> TRUE, 'mail _ fromname' => 'XX website customer ',);
4. start calling. assume that the URL /? M = home & c = index & a = send access, then we add the following method to the Application/Home/Controller/IndexController. class. php file:
The above is all the content of this article. I hope it will help you learn and support PHP.
For more PHP plug-ins, PHPMailer, and relevant articles on sending emails, please follow the PHP Chinese network!