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->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