ThinkPHP3.2.2 Integrated Phpmailer e-mail

Source: Internet
Author: User

1. Download Phpmailer;
2. Rename the class.phpmailer.php,class.smtp.php to PHPMailer.class.php and SMTP.class.php respectively;
3. And put the above two files as location:

4. Build PMailer.class.php under the Tools folder with the following code:

<?phpnamespace Tools;/** * Phpmailer e-mail Tool class * @author hzd */ class pmailer {    Private Static $CharSet=' UTF-8 ';//Set character encoding for messages    Private Static $Host=' smtp.qq.com ';//Your enterprise Post Office Server    Private Static $Username=' ******* @qq. com ';//Post Office User name (please fill in the full email address)    Private Static $Password=' ******* ';//Post Office password (email password)    Private Static $From=' ******** @qq. com ';//Email sender email Address    Private Static $FromName=' Hzd ';//e-mail Sender name    /** * e-mail * *     Public Static  function send($to,$toname,$title,$message) { Import"Tools.Mailer.PHPMailer"); Import"Tools.Mailer.SMTP");$mail=New\phpmailer ();$mail-&GT;ISSMTP ();//Send using SMTP        $mail->charset= Self::$CharSet;$mail->host = Self::$Host;//$mail->port = 25;//Set Port        $mail->smtpauth =true;//Enable SMTP Authentication feature        $mail->username = Self::$Username;$mail->password = Self::$Password;$mail->from = Self::$From;$mail->fromname = Self::$FromName;$mail->addaddress ($to,$toname);//Recipient address, can be replaced with any email message you want to receive, the format is addaddress ("Recipient Email", "Recipient name")        $mail->ishtml (true);//Set email format to HTML//whether HTML is used        $mail->subject =$title;// "phpmailer test Mail";//Mail Header        $mail->body =$message;//email content        if(!$mail->send ()) {return $mail->errorinfo; }Else{return true; }       }}

5. Call directly in the controller, the code is as follows:

<?phpnamespace Home\Controller; Use Think\Controller; class indexcontroller extends Controller {     Public  function index(){Header' Content-type:text/html;charset=utf-8 ');$mail=New\tools\pmailer ();$to="******* @qq. com";//Recipient's email address        $toname="***";//Recipient's name (can be blank)        $title=' Test ';//Theme        $message=' <a href= ' http://www.baidu.com ' > This is a test message </a> ';//Send the information        $res=$mail->send ($to,$toname,$title,$message);if($res) {Echo ' send Success '; }Else{Echo $res; }   }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ThinkPHP3.2.2 Integrated Phpmailer e-mail

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.