PHP mail sending function-ThinkPHP3.2.3 code details

Source: Internet
Author: User
First, Step 1: put down a PHPMailer plug-in on the internet. after downloading and unzipping, we only need to use two of the files. First step: go down a PHPMailer plug-in on the Internet, plug-In Address # After downloading and unzipping, we only need to use two of the files here, as shown in:

1/** 2 * function: email sending function 3 * @ param string $ to target email address 4 * @ param string $ subject (title) 5 * @ param string $ to mail content 6 * @ return bool true 7 */8 function sendMail ($ to, $ subject, $ content) {9 vendor ('phpmailer. class # smtp '); 10 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 11 $ mail = new PHPMailer (); 12 // assemble the email server 13 if (C ('mail _ SMTP ') {1 4 $ mail-> IsSMTP (); 15} 16 $ mail-> Host = C ('mail _ host '); // For Parameter explanations, see the following configuration information. Note 17 $ mail-> SMTPAuth = C ('mail _ SMTPAUTH '); 18 $ mail-> Username = C ('mail _ username'); 19 $ MAIL-> Password = C ('mail _ password '); 20 $ mail-> SMTPSecure = C ('mail _ SECURE '); 21 $ MAIL-> CharSet = C ('mail _ charset '); 22 // assemble the mail header information 23 $ MAIL-> From = C ('mail _ username'); 24 $ mail-> AddAddress ($ ); 25 $ mail-> FromName = C ('mail _ fromname'); 26 $ MAIL-> Is HTML (C ('mail _ ISHTML '); 27 // assemble the MAIL Body information 28 $ mail-> Subject = $ subject; 29 $ mail-> Body = $ content; 30 // send email 31 if (! $ Mail-> Send () {32 return FALSE; 33} else {34 return TRUE; 35} 36}


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, 6 'mail _ host' => 'smtp .163.com ', // send an email to smtp server 7'mail _ SMTPAUTH' => TRUE, 8 'mail _ username' => '2017 *** @ 163.com ', // SMTP server login USERNAME 9 'mail _ password' => '123456abc ', // SMTP server logon password 10 'mail _ SECURE '=> 'tls', 11 'mail _ charset' => 'utf-8 ', 12 'mail _ ISHTML '=> TRUE, 13 'mail _ fromname' => 'XX website customer', 14 );

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:

1
 

The above is the PHP mail sending function-ThinkPHP3.2.3 code details, more relevant content please follow the PHP Chinese network (www.php1.cn )!

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.