When working on Android, consider the ability to add email notifications, forget passwords, and reset email passwords in your app. Extreme guests add PHP to the web host and use SMTP to send e-mail (SSL-enabled) codes while using their own domain emails. Leavepaper@wangbaiyuan.cn was tested.
PHP emails with SSL support SSL
PHP emails (supports SSL) code using SMTP
Note: Please download PHPMailer_v5.1 and unzip it to the virtual host. Introduce PHPMailer's core file class.phpmailer.php.(Code comes from the Internet, the ultimate source of doubt)
//Introducing the core file of PHPMailer Using require_once to include avoiding duplicate warnings of the PHPMailer class
// Sample PHPMailer core class
$mail = new PHPMailer();
//Whether the smtp debugging is enabled for debugging? The development environment is recommended to open. The production environment can be commented out. The debugging mode is turned off by default.
$mail->SMTPDebug = 1;
// Use smtp authentication to send email, of course you can choose pop method sendmail method, etc. This article does not explain
//You can refer to http://phpmailer.github.io/PHPMailer/ for details
// smtp needs authentication This must be true
//The server address of the linked qq domain name mailbox
$mail->Host = 'smtp.qq.com';
// Set login authentication using ssl encryption
$mail->SMTPSecure = 'ssl';
// Set the remote server port number of the ssl connection to the smtp server Optional 465 or 587
$mail->Port = 465;
// Set smpp's helo header This is optional Content Any
$mail->Helo = 'Hello smtp.qq.com Server';
//Set the sender's host domain. Optional. The default is localhost. It is recommended to use your domain name.
//$mail->Hostname = 'jjonline.cn';
// Set the encoding of the sent message Optional GB2312 I like utf-8 It is said that utf8 will be garbled under certain client receiving
$mail->CharSet = 'UTF-8';
// Set the sender's name (nickname) Any content, the sender's name in front of the sender's email address of the recipient's email
$mail->FromName = 'BY Leave System';
//smtp login account here to fill in the string format qq
/ / Smtp login password here to enter the "independent password" If you set the "independent password" then fill in the password for login qq It is recommended to set "independent password"
$mail->Password = 'xxxxxxxxx';
//Set the sender's email address. Fill in the above mentioned "Sender Email"
$mail->From = 'email@example.com';
// Whether the body of the email is html-encoded Note that this is a method no longer a property true or false
//Set Recipient Email Address This method has two parameters The first parameter is the recipient email address The second parameter is the nickname that is set to this address. Different mailbox systems will automatically process changes The significance of the second parameter here Not much
$mail->addAddress('firstname.lastname@example.org','BY's leave system');
//Add multiple recipients to call the method multiple times
//$mail->addAddress('email@example.com', 'Jingjing Online User');
// Add the subject of this email
$mail->Subject = 'Example of BY mailing system';
//Add message body Set isHTML above to true, then it can be a complete html string. For example: use file_get_contents function to read the local html file
$mail->Body = "This is a <b style="color:red;">BY check-out system</b> a test case for sending mail";
// Attach an attachment for the email This method also has two parameters The first argument 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.
//The same method can be called multiple times to upload multiple attachments
//Send command Return Boolean
//PS: After testing, if the recipient does not exist, it will return true if there is no error. That is to say, before sending it, it needs some methods to detect whether the mailbox is real and effective.
$status = $mail->send();
// Simple judgments and prompts
Echo 'send email success';
Echo 'send email failed with error message: '.$mail->ErrorInfo;
This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!
Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/php-with-smtp-email-support-ssl-2.html