I am a novice, because to do the mail to send verification code, so find and collect these, I can test completely
This is 163 mailbox because the account that is not the enterprise mailbox fills in is 163 account number, but the password is the authorization code
Authorization codes are obtained in the following ways:
And then
Then look down on this page to see
The next step is code execution.
// Introduce the core files of PHPMailer Use require_once to include a warning to avoid duplicate definitions of the PHPMailer class
include ("PHP / class.smtp.php");
include ("PHP / class.phpmailer.php");
// Example PHPMailer core class
$ mail = new PHPMailer ();
// Whether to enable the debugging of smtp for development. It is recommended to open the production environment and comment out. The debug debugging mode is turned off by default.
$ mail-> SMTPDebug = 1;
// Send mail using smtp authentication method, of course you can choose pop method, sendmail method, etc. This article does not explain in detail
// You can refer to the detailed introduction in http://phpmailer.github.io/PHPMailer/
$ mail-> isSMTP ();
// smtp needs authentication, this must be true
$ mail-> SMTPAuth = true;
// link qq domain name mailbox server address
$ mail-> Host = 'smtp.163.com';
// Set login authentication using ssl encryption method. 163 is enabled by default, but qq needs this sentence.
// $ mail-> SMTPSecure = 'ssl';
// Set the remote server port number for ssl to connect to the smtp server Optional 465 or 587
$ mail-> Port = 25;
// Set the helo message header of smtp. This content is optional.
// $ mail-> Helo = 'Hello smtp.163.com Server';
// Set the sender's host domain. Optional. Default is localhost. Any content is recommended. It is recommended to use your domain name.
// $ mail-> Hostname = 'jjonline.cn';
// Set the encoding of the sent email. Optional GB2312. I like UTF-8. It is said that UTF8 will be garbled when received by some clients.
$ mail-> CharSet = 'UTF-8';
// Set the sender's name (nickname) Any content, which is displayed in front of the sender's email address of the recipient's email
$ mail-> FromName = 'Sender's name';
// smtp login account Enter 163 email account here
$ mail-> Username = '163 Email Account';
// smtp login password
$ mail-> Password = 'Authorization Code';
// Set the sender's email address Here, fill in the "Sender's Email" mentioned above
$ mail-> From = 'The "Sender mailbox is the same as the 163 mailbox above" mentioned above;';
// Whether the message body is html encoded Note that this is a method and is no longer a property 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 a mailbox with a different nickname. Not big
$ mail-> addAddress ('Email Address');
// Add multiple recipients, you can call the method multiple times
//$mail->addAddress('xxx@163.com','Test ');
// Add the subject of the message
$ mail-> Subject = 'Test';
// Add mail body Set isHTML to true above, it 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 message This method also has two parameters. The first parameter is the directory where the attachment is stored (either relative or absolute). The second parameter is the name of the attachment in the email attachment.
//$mail->addAttachment('./d.jpg','mm.jpg ');
// Same method can be called multiple times to upload multiple attachments
//$mail->addAttachment('./Jlib-1.1.0.js','Jlib.js');
// Send command returns boolean
// PS: After testing, if the recipient does not exist, it will return true if there is no error, that is, before sending, you need some methods to check whether the mailbox is real and valid
$ status = $ mail-> send ();
// Simple judgment and prompt information
if ($ status) {
echo 'Send email successfully';
} else {
echo 'Failed to send mail, error message:'. $ mail-> ErrorInfo;
}
QQ now also want to obtain authorization code login access mode settings-"account
// Introduce the core files of PHPMailer Use require_once to include a warning to avoid duplicate definitions of the PHPMailer class
include ("PHP / class.smtp.php");
include ("PHP / class.phpmailer.php");
// Example PHPMailer core class
$ mail = new PHPMailer ();
// Whether to enable the debugging of smtp for development. It is recommended to open the production environment and comment out. The debug debugging mode is turned off by default.
$ mail-> SMTPDebug = 1;
// Send mail using smtp authentication method, of course you can choose pop method, sendmail method, etc. This article does not explain in detail
// You can refer to the detailed introduction in http://phpmailer.github.io/PHPMailer/
$ mail-> isSMTP ();
// smtp needs authentication, this must be true
$ mail-> SMTPAuth = true;
// link qq domain name mailbox server address
$ mail-> Host = 'smtp.qq.com';
// Set login authentication using SSL encryption qq requires SSL login authentication
$ mail-> SMTPSecure = 'ssl';
// Set the remote server port number for ssl to connect to the smtp server Optional 465 or 587
$ mail-> Port = 465;
// Set the helo message header of smtp. This content is optional.
// $ mail-> Helo = 'Hello smtp.163.com Server';
// Set the sender's host domain. Optional. Default is localhost. Any content is recommended. It is recommended to use your domain name.
// $ mail-> Hostname = 'jjonline.cn';
// Set the encoding of the sent email. Optional GB2312. I like UTF-8. It is said that UTF8 will be garbled when received by some clients.
$ mail-> CharSet = 'UTF-8';
// Set the sender's name (nickname) Any content, which is displayed in front of the sender's email address of the recipient's email
$ mail-> FromName = 'wangkun';
// smtp login account Here, fill in the qq number in string format.
$ mail-> Username = 'Just the qq number';
// smtp login password fill in "independent password" If set "independent password" then fill in the password for login qq It is recommended to set "independent password" ssawncngrsjbbbdc
$ mail-> Password = 'Authorization code obtained by qq';
// Set the sender's email address Here, fill in the "Sender's Email" mentioned above
$ mail-> From = 'Enter your full email account';
// Whether the message body is html encoded Note that this is a method and is no longer a property 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 a mailbox with a different nickname. Not big
$ mail-> addAddress ('Recipient Email');
// Add multiple recipients, you can call the method multiple times
//$mail->addAddress('xxx@163.com','Jingjing Online User ');
// Add the subject of the message
$ mail-> Subject = 'Subject';
// Add mail body Set isHTML to true above, it 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 message This method also has two parameters. The first parameter is the directory where the attachment is stored (either relative or absolute). The second parameter is the name of the attachment in the email attachment.
//$mail->addAttachment('./d.jpg','mm.jpg ');
// Same method can be called multiple times to upload multiple attachments
//$mail->addAttachment('./Jlib-1.1.0.js','Jlib.js');
// Send command returns boolean
// PS: After testing, if the recipient does not exist, it will return true if there is no error, that is, before sending, you need some methods to check whether the mailbox is real and valid
$ status = $ mail-> send ();
// Simple judgment and prompt information
if ($ status) {
echo 'Send email successfully';
} else {
echo 'Failed to send mail, error message:'. $ mail-> ErrorInfo;
}
That's it, okay?
How do I download Phpmailer code packs?
Phpmailer Project Address: Https://github.com/PHPMailer/PHPMailer
Download the Phpmailer after decompression to thin body, only need class.phpmailer.php, class.pop3.php, class.smtp.php and phpmailerautoload.php four files, language folder can not be, which is mainly used for debug debugging display information.
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.