Thinkphp3.2PHPMailer sends an email

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

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.