Using Phpmailer to implement PHP e-mail functionality

Source: Internet
Author: User
Tags server port

The first step:

Open URL https://github.com/PHPMailer/PHPMailer/download Phpmailer,phpmailer need PHP sockets extension support, and login QQ mailbox SMTP server must be encrypted by SSL, P HP also has to include 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 the basic code of the message

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 = ' [email protected] ';//SMTP login password using the generated authorization code $mail->password = ' ********** ';/ Set the sender's email address with the login account $mail->from = ' [email protected] ';//The message body is HTML-encoded note here is a method $mail->ishtml (true); Set the recipient's mailbox address $mail->addaddress (' [email protected] ');//Add multiple recipients by calling the method multiple times $mail->addaddress (' [email  Protected]///Add the subject of the message $mail->subject = ' message 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's the message is-be-sent from $mail->setfrom ($config [' Smtp_ User '], $config [' email_id ']),//reply to address//$mail->addreplyto (' [email protected] ', ' 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 ();}

  

Using Phpmailer to implement PHP e-mail functionality

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.