thinkphp how to send mail via Phpmailer in Enterprise mailbox

Source: Internet
Author: User
Tags how to send mail using git
May be because of the need for work, to the site users to send mail, but so many customers can not be a part of the hair, then give you a good way to use PHP to help you solve this tedious task.

I have been using 163 mailbox to send the files that need to be processed, but if the operation is too frequent "or a different problem", will cause the send failed, on the contrary now with QQ seems to have not appeared similar situation, but QQ mailbox configuration and 163 have a lost not the same, I still paste a bit, afraid of friends stepping on the pit, The following words do not say much, come together to see the detailed introduction.

Advantages of Phpmailer:

Can be run on top of any platform

Support for SMTP authentication

Specify multiple recipients, CC address, send address and reply address when sending mail; Note: Add cc, BCC only under the win platform SMTP mode support

Supports multiple message encodings including: 8bit,base64,binary and Quoted-printable

Support for redundant SMTP servers, that is, you can specify the primary SMTP server address and can only specify the backup SMTP server

Supports mail with attachments, and can add attachments in any format to your message-your server, of course, has a large enough bandwidth to support it.

Custom message header information, which is similar to sending header information in PHP via the header function

Support to make the message body HTML content, you can insert a picture in the body of the message

Flexible Debug Support

Tested and compatible SMTP servers include: Sendmail,qmail,postfix,imail,exchange, etc.

1. Download Phpmailer

Because there are a lot of versions, I am here to use the package of the version I used to share, with other versions of Friends can use their own good

Download Address: Http://xiazai.jb51.net/201711/yuanma/phpmailer (jb51.net). rar

2. Place Phpmailer

I created a folder named "Plugin" in the root directory dedicated to all types of plugins, and then placed the Phpmailer directly under the Plugin folder


3. Be flattered to masturbate

I will be on my side of the stacking up, we can modify as necessary

function sendMail ($to, $title, $content) {require ('./plugin/phpmailer/ Class.phpmailer.php ');  try {$mail = new \phpmailer (true);  $mail->issmtp ();  $mail->smtpsecure = ' SSL ';  $mail->charset = ' UTF-8 '; $mail->smtpauth = true; Open authentication $mail->port = 465;  NetEase for the $mail->host = "smtp.qq.com"; $mail->username = "******";  QQ here for mailbox prefix name 163 is the mailbox name $mail->password = "******";  $mail->addreplyto ("****** @qq. com", "******");//reply to address $mail->from = "****** @qq. com";  $mail->fromname = ' ****** ';  $mail->addaddress ($to);  $mail->subject = $title;  $mail->body = $content; $mail->altbody = "To view the message, please use an HTML compatible email viewer!"; Alternate display $mail->wordwrap = 80 When the message does not support HTML; Sets the length of the string per line//$mail->addattachment ("F:/test.png");  Attachments can be added $mail->ishtml (true);  $mail->send (); Echo ' Mail has been sent '; } catch (Phpmailerexception $e) {echo "message sent failed:". $e->errormessage ();}} 


Copy the above code changes directly into your control machine

Places to be aware of:

$mail->port = 465; NetEase 163 25$mail->host = "smtp.qq.com"; $mail->username = "* *"; QQ Here is the mailbox prefix name 163 for the mailbox name $mail->password = "******";


This piece, NetEase's port is 25

Username words, NetEase directly use the mailbox name, QQ mailbox Please enter the mailbox prefix "User name" "Eg.1214982635@qq.com Please enter 1214982635"

Password NetEase directly enter the email password can "have authorization code transmission authorization Code", QQ please lose authorization code, send a text message can generate


Believe that you have seen these cases you have mastered the method, more wonderful please pay attention to the PHP Chinese network other related articles!

Related reading:

PHP deployment Environment using GIT

Some use cases of git

JavaScript data types and git use code explained

Related Article

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.