Joke Collection Website - Blessing messages - How to send mail in thinkphp3. 1

How to send mail in thinkphp3. 1

ThinkPHP mail sending function method

/**

* system mail sending function

* @ param string $ sent to the recipient's mailbox.

* @param string $name the name of the recipient

* @param string $subject email subject

* @param string $body email content

* @param string $attachment attachment list

* @return Boolean value

*/

Function think _ send _ mail($ to, $name, $ subject ='', $ body ='', $ attachment = null ){

$ config = C(‘THINK _ EMAIL‘);

Supplier ('phmailer.class # phmailer'); //Import class.PHPMailer.php files from the phpmailer directory.

$ mail = new PHP mailer(); //PHPMailer object

$ mail-& gt; CharSet =‘UTF-8‘; //Set the mail code, which defaults to ISO-8859- 1. If you send Chinese, you must set this item, otherwise there will be garbled code.

$ mail-& gt; ISS MTP(); //Set SMTP service.

$ mail-& gt; SMTPDebug = 0; //Turn off SMTP debugging.

// 1 = Errors and messages

// 2 = Message only

$ mail-& gt; SMTPAuth = true// Enable SMTP authentication.

$ mail-& gt; SMTPSecure =‘SSL‘; //Use security protocols

$ mail-& gt; HOST = $ config【‘SMTP _ HOST‘】; // SMTP server

$ mail-& gt; PORT = $ config【‘SMTP _ PORT‘】; Port number of SMTP server

$ mail-& gt; username = $ config【‘SMTP _ USER‘】; // SMTP server user name

$ mail-& gt; password = $ config【‘SMTP _ PASS‘】; // SMTP server password

$ mail-& gt; set FROM($ config【‘FROM _ EMAIL‘】,$ config【‘FROM _ NAME‘】);

$ replyemail = $ config ['reply email']? $ config【‘REPLY _ EMAIL‘】:$ config【‘FROM _ EMAIL‘】;

$ REPLY NAME = $ config【‘REPLY _ NAME‘】? $ config【‘REPLY _ NAME‘】:$ config【‘FROM _ NAME‘】;

$ mail-& gt; AddReplyTo($ reply email,$ reply name);

$ mail-& gt; Subject = $ subject

$ mail-& gt; MsgHTML($ body);

$ mail-& gt; AddAddress($ to,$ name);

If(is _ array($ attachment)){// Add attachment.

foreach($ attachment as $ file ){

is _ file($ file)& amp; & amp$ mail-& gt; add attachment($ file);

}

}

Return to $ TERM-> Send()? true:$ mail-& gt; ErrorInfo

This function can only be used in ThinkPHP and needs the support of phpmailer extension;

The location directory of phpmailer extension is thinkphp/extend/vendor/phpmailer/class.phpmailer.php.

Download address of phpmail:

/a/Apache-extras . org/p/PHP mailer

To use this feature, you must add the following configuration items to the project.

//Mail configuration

THINK _ EMAIL‘= & gt; Array (

SMTP _ HOST‘= & gt; Smtp.aaa.com', //SMTP server

SMTP _ PORT‘= & gt; 465', //SMTP server port

SMTP _ USER‘= & gt; Mail @ aaa.com, //SMTP server user name.

SMTP _ PASS‘= & gt; Password', //SMTP server password

‘FROM _ EMAIL‘= & gt; Mail @ aaa.com,//The sender's email.

FROM _ NAME‘= & gt; ThinkPHP,//sender's name

Reply to e-mail' ‘=>;; ,//Reply to e-mail (leave blank as sender's e-mail)

REPLY _ NAME‘= & gt; ,//Reply to the name (if left blank, the name of the sender)

),