Thinkphp uses phpmailer to send emails

Source: Internet
Author: User
This article mainly introduces how thinkphp uses phpmailer to send mails, including configuring the mail class, setting parameters, and sending mail test steps, which has some practical value, for more information, see

This article mainly introduces how thinkphp uses phpmailer to send mails, including configuring the mail class, setting parameters, and sending mail test steps, which has some practical value, for more information, see

This example describes how thinkphp uses phpmailer to send emails. Share it with you for your reference. The specific analysis is as follows:

Phpmailer is the preferred email sending plug-in for php developers. Next I will introduce how to integrate phpmailer into the thinkphp framework. If you are interested, refer to it.

Phpmailer has a powerful email sending function. For a real experience today, I will briefly introduce the configuration, which I used in thinkphp.

Configuration steps:

1. Configure the mail sending class in the background at admin/common. php. The Code is as follows:

The Code is as follows:

Function sendmail ($ tomail, $ title, $ content)
{
/* Email setting information */
$ Email_set = C ('email _ set ');
Vendor ('phpmailer. class # phpmailer ');
Vendor ("phpmailer. class # smtp"); // optional; otherwise, it will include

$ Mail = new PHPMailer (true); // instantiate the PHPMailer class. true indicates that an exception is thrown when an error occurs.

$ Mail-> IsSMTP (); // use SMTP
$ Mail-> CharSet = "UTF-8"; // sets the email Encoding
$ Mail-> Host = $ email_set ['host']; // SMTP server
$ Mail-> SMTPDebug = 1; // enable SMTP debugging 1 = errors 2 = messages
$ Mail-> SMTPAuth = true; // The server must be verified.
$ Mail-> Port = $ email_set ['Port']; // set the port
// $ Mail-> SMTPSecure = "ssl ";
/*
$ Mail-> SMTPSecure = "ssl ";
$ Mail-> Host = "smtp.gmail.com ";
$ Mail-> Port = 465;
*/

$ Mail-> Username = $ email_set ['email _ user']; // user Account of the SMTP server
$ Mail-> Password = $ email_set ['email _ pwd']; // Password of the SMTP server
$ Mail-> AddReplyTo ($ email_set ['email '], $ email_set ['email _ name']); // The recipient replies to this email address when replying, this method can be executed multiple times.
If (is_array ($ tomail )){
Foreach ($ tomail as $ m ){
$ Mail-> AddAddress ($ m, 'user ');
}
} Else {
$ Mail-> AddAddress ($ tomail, 'user ');
}

$ Mail-> SetFrom ($ email_set ['email '], $ email_set ['email _ name']);
// $ Mail-> AddAttachment ('./img/phpmailer.gif'); // Add an attachment. If multiple attachments exist, repeat this method.
$ Mail-> Subject = $ title;

// The email content is as follows:
$ Mail-> Body = $ content;
$ Mail-> IsHTML (true );

// $ Body = file_get_contents('tpl.html '); // retrieves html webpage content
// $ Mail-> MsgHTML (eregi_replace ("[]", '', $ body ));

Return $ mail-> Send ()? True: false;
}


2: Configure parameters in the configuration file. The Code is as follows:

The Code is as follows:

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.