Provides various official and user-released code examples. For code reference, you are welcome to learn Thinkphp3.2 PHPMailer and send emails in combination with QQ enterprise mail.
Download the attachment PHPMailer and decompress it to ThinkPHP \ Library \ Vendor.
Create function. php In the Common folder
/**
* Email sending Function
*/
Function sendMail ($ to, $ title, $ content ){
Vendor ('phpmailer. phpmailerautoload ');
$ Mail = new PHPMailer (); // instantiate
$ Mail-> IsSMTP (); // enable SMTP
$ Mail-> Host = C ('mail _ host'); // name of the smtp server (qq mailbox is used as an example here)
$ Mail-> SMTPAuth = C ('mail _ SMTPAUTH '); // enable smtp authentication
$ Mail-> Username = C ('mail _ username'); // your mailbox name
$ Mail-> Password = C ('mail _ password'); // Email PASSWORD
$ Mail-> From = C ('mail _ from'); // The sender address (that is, your email address)
$ Mail-> FromName = C ('mail _ fromname'); // sender's name
$ Mail-> AddAddress ($ to, "dear customer ");
$ Mail-> WordWrap = 50; // you can specify the length of each line.
$ Mail-> IsHTML (C ('mail _ ISHTML '); // whether the email is in HTML Format
$ Mail-> CharSet = C ('mail _ charset'); // sets the email encoding.
$ Mail-> Subject = $ title; // mail Subject
$ Mail-> Body = $ content; // mail content
$ Mail-> AltBody = "this is a plain text body in the non-profit HTML email client"; // The mail body does not support HTML alternate display.
Return ($ mail-> Send ());
}
Add configuration file
Config. php
// Configure the email sending server
'Mail _ host' => 'smtp .exmail.qq.com ', // smtp server name
'Mail _ SMTPAUTH '=> TRUE, // enable smtp authentication
'Mail _ username' => 'jufengjituan @ gsjfjt.com ', // your mailbox name
'Mail _ from' => 'jufengjituan @ gsjfjt.com ', // sender address
'Mail _ fromname' => 'jufeng group', // sender's name
'Mail _ password' => '******', // Email PASSWORD
'Mail _ charset' => 'utf-8', // sets the email encoding.
'Mail _ ISHTML '=> TRUE, // whether the email is in HTML Format
Finally, use PHPMailer to send emails.
Public function add (){
If (SendMail ($ _ POST ['mail'], $ _ POST ['title'], $ _ POST ['content'])
$ This-> success ('sent successfully! ');
Else
$ This-> error ('sending failed ');
}
PHPMailer.rar (190.72 KB download: 4159 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB