Php uses phpmailer to send mails and phpmailer to send mails

Source: Internet
Author: User
Tags email account ssl connection

Php uses phpmailer to send mails and phpmailer to send mails

I am a newbie. I want to send the verification code via email, so I can find and collect the verification code.

This is the 163 mailbox because the account entered in the enterprise mailbox is not the 163 account, but the password is the authorization code

The authorization code is obtained as follows:

Then

Then you can see it in the lower part of this page.

The next step is to execute the code.

// Introduce the PHPMailer core file and use require_once to contain warnings to avoid repeated definitions of the PHPMailer class include ("PHP/class. smtp. php "); include (" PHP/class. phpmailer. php "); // sample PHPMailer core class $ mail = new PHPMailer (); // whether to enable smtp debug for debugging the development environment. We recommend that you enable the production environment annotation to disable the debug debugging mode by default. $ mail-> SMTPDebug = 1; // use smtp authentication to send emails, of course, you can select the pop sendmail method. Otherwise, please do not elaborate on this article. // For details, refer to http://phpmailer.github.io/phpmailer/for details on $ mail-> isSMTP (); // for smtp authentication, the value must be true $ mail-> SMTPAuth = true; // the address of the server connecting the qq domain name mailbox $ mail-> Host = 'smtp .163.com '; // set the use of ssl encryption for logon authentication because 163 is enabled by default, so do not ask qq For this sentence // $ mail-> SMTPSecure = 'ssl '; // set the remote server Port number for ssl connection to the smtp server. Optional values: 465 or 587 $ mail-> Port = 25; // set the smtp helo message header, which can have no content. // $ mail-> Helo = 'Hello smtp.163.com Server'; // set the sender's host domain to have any content without the localhost content by default, we recommend that you use your domain name // $ mail-> Hostname = 'jjonline. cn '; // set the encoding of the sent mail. Optional. GB2312. I like UTF-8. It is said that utf8 will garbled characters in some clients. $ mail-> CharSet = 'utf-8 '; // set any sender name (nickname). The sender name before the recipient's email address $ mail-> FromName = 'sender name' is displayed '; // enter the account for smtp Logon As the 163 email account. Then, enter $ mail-> Username = '1970 email account'. // smtp logon Password $ mail-> Password = 'authorization Code '; // set the sender's email address. Enter the aforementioned "sender's email address" $ mail-> From = 'the aforementioned mentioned "sender's email address is the same as the above 163 email address "'; // whether the email body is html encoded. Note that a method is no longer a property of true or false $ mail-> isHTML (true ); // set the recipient's email address. This method has two parameters. The first parameter is the recipient's email address. The second parameter is the nickname set for this address. Different email addresses are automatically processed and changed. Here, the second parameter is used. not significant $ mail-> addAddress ('email address '); // Add multiple recipients to call the method multiple times. // $ mail-> addAddress ('xxx @ 163.com ', 'test '); // Add the Subject of the email $ mail-> Subject = 'test'; // set isHTML to true above the email body, which can be a complete html string, for example: use the file_get_contents function to read the local html file $ mail-> Body = "Test Verification Code ". $ token; // Add an attachment to the email. This method also has two parameters. The first parameter is the directory where the attachment is stored (either relative directory or absolute directory) the second parameter is the name of the attachment in the email attachment // $ mail-> addAttachment ('. /d.jpg','mm.jpg '); // you can call this method multiple times to upload multiple attachments. // $ mail-> addAttachment ('. /Jlib-1.1.0.js ', 'jlib. js '); // Boolean value returned by the sending command // PS: after testing, if the recipient does not exist, if no error is returned, true is returned. That is, you need some methods to check whether the email address is valid before sending the email. $ status = $ mail-> send (); // simple judgment and prompt message if ($ status) {echo 'email sending successfully';} else {echo 'email sending failed, error message :'. $ mail-> ErrorInfo ;}

Qq now also needs to obtain the authorization code login acquisition method settings-"account

// Introduce the PHPMailer core file and use require_once to contain warnings to avoid repeated definitions of the PHPMailer class include ("PHP/class. smtp. php "); include (" PHP/class. phpmailer. php "); // sample PHPMailer core class $ mail = new PHPMailer (); // whether to enable smtp debug for debugging the development environment. We recommend that you enable the production environment annotation to disable the debug debugging mode by default. $ mail-> SMTPDebug = 1; // use smtp authentication to send emails, of course, you can select the pop sendmail method. Otherwise, please do not elaborate on this article. // For details, refer to http://phpmailer.github.io/phpmailer/for details on $ mail-> isSMTP (); // for smtp authentication, the value must be true $ mail-> SMTPAuth = true; // the address of the server connecting the qq domain name mailbox $ mail-> Host = 'smtp .qq.com '; // set ssl encryption for logon to authentication qq. ssl logon authentication is required. $ mail-> SMTPSecure = 'ssl '; // set the remote server Port number for ssl connection to the smtp server. Optional values: 465 or 587 $ mail-> Port = 465; // set the smtp helo message header, which can have no content. // $ mail-> Helo = 'Hello smtp.163.com Server'; // set the sender's host domain to have any content without the localhost content by default, we recommend that you use your domain name // $ mail-> Hostname = 'jjonline. cn '; // set the encoding of the sent mail. Optional. GB2312. I like UTF-8. It is said that utf8 will garbled characters in some clients. $ mail-> CharSet = 'utf-8 '; // set the sender's name (nickname) to any content, and display the sender's name before the recipient's email address $ mail-> FromName = 'hangzhou '; // enter the QQ number in the string format for the smtp Logon account $ mail-> Username = 'as long as the QQ number is good '; // enter the smtp logon Password here as "independent Password". If "independent Password" is set, enter the logon qq Password. We recommend that you set "independent Password" ssawncngrsjbbbdc $ mail-> Password = 'qq get authorization code '; // set the sender's email address. Enter "sender's email address" $ mail-> From = 'Enter the complete email account '; // whether the email body is html encoded. Note that a method is no longer a property of true or false $ mail-> isHTML (true ); // set the recipient's email address. This method has two parameters. The first parameter is the recipient's email address. The second parameter is the nickname set for this address. Different email addresses are automatically processed and changed. Here, the second parameter is used. not significant $ mail-> addAddress ('recipient mailbox '); // Add multiple recipients to call the method multiple times. // $ mail-> addAddress ('xxx @ 163.com ', 'jingjing online user '); // Add the Subject of the email $ mail-> Subject = 'title'; // set isHTML to true at the top of the email body, which can be a complete html string, for example: use the file_get_contents function to read the local html file $ mail-> Body = "your content ". $ token; // Add an attachment to the email. This method also has two parameters. The first parameter is the directory where the attachment is stored (either relative directory or absolute directory) the second parameter is the name of the attachment in the email attachment // $ mail-> addAttachment ('. /d.jpg','mm.jpg '); // you can call this method multiple times to upload multiple attachments. // $ mail-> addAttachment ('. /Jlib-1.1.0.js ', 'jlib. js '); // Boolean value returned by the sending command // PS: after testing, if the recipient does not exist, if no error is returned, true is returned. That is, you need some methods to check whether the email address is valid before sending the email. $ status = $ mail-> send (); // simple judgment and prompt message if ($ status) {echo 'email sending successfully';} else {echo 'email sending failed, error message :'. $ mail-> ErrorInfo ;}

In this way, you can

How do I download the PHPMailer code package?

PHPMailer Project address: https://github.com/PHPMailer/PHPMailer

After the downloaded PHPMailer is decompressed, you only need class. phpmailer. php, class. pop3.php, class. smtp. php and PHPMailerAutoload. four php files, which can be used for the language folder or not, are mainly used for display information during debug debugging.

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.