thinkphp Send mail using 163 mailbox

Source: Internet
Author: User

thinkPHP3.2.3 e-Mail using 163 email (i) preface

The first time to write a blog, the main purpose is to share some of the experience of tapping the code and sorting out their knowledge for later review.

I used to be looking for a tutorial using QQ mailbox to send mail through thinkphp, found that the last card in the mailbox server password this piece, as if it is because there is no SSL, and then I found that with 163 mailbox is easy to achieve, and finally decided to use 163 mailbox.

(b) Pre-preparation

First you have to have a 163-mailbox account. Register login after entering setup to open POP3/SMTP server.

Need to verify the phone, the verification will let you enter the authorization code, remember this authorization code, will be used later.

If the original has been turned on and forgot the authorization code, you can go to the mobile phone text inside the rollover, may be found; or click the client authorization code to reset

(c) Part of the Code

Phpmailer download, download and put Phpmailer decompression in the/thinkphp/library/vendor directory

config.php configuration:

' Mail_host ' = ' smtp.163.com ',//name of the SMTP server' Mail_smtpauth ' =TRUE,//Enable SMTP authentication' Mail_username ' = ' zha****[email protected] ',//Sender's mailbox name' Mail_password ' = ' OLAGBQSYEYHILCWU ',//163 Mailbox Sender Authorization Password' Mail_from ' = ' zha****[email protected] ',//Sender e-mail address' Mail_fromname ' = ' The sky is still snowing ',//Sender's name' Mail_charset ' = ' utf-8 ',//set up message encoding' Mail_ishtml ' =TRUE,//whether HTML-formatted messages

  

function.php Public functions:

/** Send mail * @param $to String * @param $title String * @param $content String * @return bool **/functionSendMail ($to,$title,$content) {Vendor (' Phpmailer.phpmailerautoload '); $mail=NewPhpmailer ();//instantiation of $mail->ISSMTP ();//Enable SMTP $mail->host=c (' Mail_host ');//name of the SMTP server (for example, QQ mailbox here) $mail->smtpauth = C (' Mail_smtpauth ');//Enable SMTP authentication $mail->username = C (' Mail_username ');//Sender Mailbox Name $mail->password = C (' Mail_password ');//163 Mailbox Sender Authorization Password $mail->from = C (' Mail_from ');//Sender address (i.e. your e-mail address) $mail->fromname = C (' Mail_fromname ');//Sender's name $mail->addaddress ($to, "Dear Customer"); $mail-WordWrap= 50;//set character length per line $mail->ishtml (C (' mail_ishtml '));//whether HTML-formatted messages $mail->charset=c (' Mail_charset ');//set up message encoding $mail->subject =$title;//Message Subject $mail->body =$content;//Message Content $mail->altbody = "This is a plain text body in a non-profit HTML email client";//the message body does not support alternate display of HTML return($mail-Send ());}

Finally, call SendMail () in the controller.

thinkphp Send mail using 163 mailbox

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.