Phpmailer using PHP to send email case resolution

Source: Internet
Author: User
Tags php send mail server port
This time to bring you phpmailer use PHP to send e-mail case resolution, phpmailer the use of PHP to send e-mail attention to what, the following is the actual case, together to see.

The first step: open the URL download phpmailer,phpmailer need PHP sockets extension support, and login QQ mailbox SMTP server must be encrypted by SSL, PHP also contains OpenSSL support.

Step Two: use the phpinfo () function to view the socket and OpenSSL extension information (WAMP server has enabled the extension by default).

If OpenSSL is not turned on, open the php.ini file.

First check the php.ini, if Extension=php_openssl.dll exists, remove the previous comment '; ' If it exists, add extension=php_openssl.dll if there is no such line.

Phpmailer Core File

Step Three: QQ Mailbox Settings

All major mailboxes support the SMTP protocol, but not all mailboxes are turned on by default, and you can open them manually in the settings of your mailbox.

Third-party services after providing the account and password, you can log in to the SMTP server, through which to control the way the mail transfer.

Fourth Step: turn on the SMTP service

Select the IMAP/SMTP service and click on the service to open

Fifth Step: Verify the Secret warranty

Send SMS "Configure mail client" to 1069-0700-69

Sixth step: Get the Authorization code

SMTP Server Authentication password, need safekeeping (PS: password directly without space)

Seventh Step: php Send mail

Basic code

The following code demonstrates how Phpmailer is used, and note the configuration process for the Phpmailer instance.

Introduction of Phpmailer's core document require_once ("phpmailer/class.phpmailer.php"); Require_once ("phpmailer/class.smtp.php"); Instantiate the Phpmailer core class $mail = new Phpmailer ();//Whether to enable debug for SMTP debugging development environment It is recommended to turn on the production environment comments off can be turned off by default Debug debug mode $mail->smtpdebug = 1 ;//Use SMTP authentication to send mail $mail->issmtp ();//SMTP requires authentication this must be True$mail->smtpauth = true;//link QQ domain Mailbox server address $mail->host = ' smtp.qq.com ';//set to use SSL encryption to login authentication $mail->smtpsecure = ' SSL ';//Set SSL to connect the SMTP server to the remote server port number $mail->port = 465;// Set the encoding of the sent message $mail->charset = ' UTF-8 ';//Set the sender's nickname to display the sender's name before the sender's email address of the recipient message $mail->fromname = ' sender nickname ';//SMTP login account QQ mailbox can $mail->username = ' 12345678@qq.com ';//SMTP login password using the generated authorization code $mail->password = ' ********** ';//Set the sender's email address with the login account $mail->from = ' 12345678@qq.com ';//whether the message body is HTML-encoded note here is a method $mail->ishtml (true);//Set the recipient's mailbox address $mail-> AddAddress (' 87654321@qq.com ');//Add multiple recipients by calling the method multiple times $mail->addaddress (' 87654321@163.com ');//Add the subject of the message $mail-> Subject = ' mail subject ';//Add message body $mail->body = ' 

I use the code in thinkphp5.0

/*** Mail Send * @param $to recipient * @param string $subject message header * @param string $content message content (content after HTML template rendered) * @throws exception* @thr oWS phpmailerexception*/function send_email ($to, $subject = ", $content =") {Vendor (' Phpmailer.  Phpmailerautoload ');//require_once ' vendor/phpmailer/phpmailerautoload.php ';  $mail = new Phpmailer;  $arr = db (' config ')->where (' Inc_type ', ' SMTP ')->select ();  $config = convert_arr_kv ($arr, ' name ', ' value '); $mail->charset = ' UTF-8 '; Set the message encoding, default iso-8859-1, if the text must be set, otherwise garbled $mail->issmtp ();//enable SMTP debugging//0 = off (for production use)//1 = CL   Ient messages//2 = client and server messages $mail->smtpdebug = 0;//Debug Output format//$mail->debugoutput = ' html ';//SMTP server  $mail->host = $config [' smtp_server '];//Port-likely to IS, 465 or 587 $mail->port = $config [' Smtp_port ']; if ($mail->port = = = 465) $mail->smtpsecure = ' SSL ';//Use security protocol//whether to using SMTP authentication $mail->smtpauth = true;//Send mailbox $mail->username = $config [' Smtp_user '];//password $mail->password = $config [' smtp_pwd '];//set who the message was to be sent from $mail->setfrom ($config [' Smtp_us Er '], $config [' email_id ']),//reply to address//$mail->addreplyto (' replyto@example.com ', ' first Last ');//Receive Mail Party if (Is_array ($    To) {foreach ($to as $v) {$mail->addaddress ($v);  }}else{$mail->addaddress ($to); } $mail->ishtml (TRUE);//Send As html//title $mail->subject = $subject;//html content conversion $mail->msghtml ($content);//rep Lace the plain text body with one created manually//$mail->altbody = ' This is a plain-text message body ';//Add attachment//$mail- >addattachment (' images/phpmailer_mini.png ');//send the message, check for errors return $mail->send ();}

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

PHP Bubble Sort using detailed

PHP implementation of two fork tree depth and breadth first traversal algorithm steps

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.