PHP plugin PHPMailer sends emails

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.