Address of PHPMailer project: PHPMailer uses git command to clone to the local area, or directly click "Download ZIP" at the lower right of the project page to obtain the complete PHPMailer code package, and then decompress it locally.
Step 1: Enable our QQ mailbox to send mail.
How can I say that I can send mail here? In fact, all our mailboxes can send emails, but if we want to send emails in our website, we must set up our QQ mailbox, because our website now exists as a third-party client.
Step 1: Enable our QQ mailbox to send mail. In fact, all our mailboxes can send emails, but if we want to send emails in our website, we must set up our QQ mailbox, because our website now exists as a third-party client.
Since we will use SMTP server to send it later, it is suggested to open the first two items here! When you click Open, it will prompt:
When you complete the above steps, you will get an authorization code. You can copy it first, and we will use it later (if you open two items, you will get two authorization codes, and use the last authorization code! Or click the generate authorization code below to get a new authorization code, which must be the latest! )。
Step 2: Enable our php to use qq mailbox to send mail. PHPMailer needs socket extension support of PHP, while PHPMailer needs ssl encryption when linking QQ domain mailbox, and fixed PHP needs openssl support, so you can check phpinfo. If the following two items exist, you can use them regardless of the openssl version number; Many Php in virtual hosts don't support openssl extensions, and you may be miserable.
Step 3: do some processing on PHPMailer. Because there are many files in the PHPMailer folder we downloaded, we don't need them, so we don't need to waste these memories. We can streamline this folder. I only keep the following documents here: class.phpmailer.php, class.phpmaileroauth.php, class.pop3.php, class.smtp.php and PHPMailerAutoload.php.
/* Method of sending mail
*@param? $to: the receiver? $title: title? $content: the content of the email
*@return? Bull? Really: Did you send it successfully? False: sending failed.
*/function? Sendmail ($ to, $ title, $ content){// Introduce the core file of PHPMailer? Use require_once to include a warning to avoid repeated definitions of the PHPMailer class.
require _ once(" PHP mailer/class . PHP mailer . PHP "); ?
require _ once(" PHP mailer/class . SMTP . PHP "); //instantiate the PHPMailer core class
$ mail? =? New? PHP mailer(); //Do you want to enable smtp debugging? Is the development environment recommended to open? Can you comment out the production environment? Debugging mode is turned off by default.
$ mail-& gt; SMTPDebug? =? 1; //Use smtp authentication to send mail.
$ mail-& gt; ISS MTP(); //smtp needs authentication? This must be true.
$ mail-& gt; SMTP auth = true//Server address of QQ domain email address.
$ mail-& gt; Moderator? =? SMTP . QQ . com '; //Use ssl encryption to set login authentication.
$ mail-& gt; SMTPSecure? =? SSL '; //Set the port number of the remote server where ssl connects to smtp server. The previous default was 25, but now the new one seems to be unavailable? Optional 465 or 587
$ mail-& gt; Port? =? 465; //set the helo header of smtp? This is an optional content.
//? $ mail-& gt; Shiloh? =? Hello? smtp.qq.com? Server';
//Set the sender's host domain? Dispensable? The default is localhost? Any content, it is recommended to use your domain name.
$ mail-& gt; Host name? =? ''; //Set the encoding for sending mail? Optional GB23 12? I like utf-8? It is said that utf8 will be garbled when some clients receive messages.
$ mail-& gt; Character set? =? UTF-8’; //Set the sender's name (nickname)? Anything that shows the sender's name before the sender's email address of the recipient's mail.
$ mail-& gt; FromName? =? LSGO laboratory; //smtp login account? Fill in the qq number in string format here.
$ mail-& gt; User name? = ' 12345678 @ QQ . com '; //Password for //smtp login? Use the generated authorization code (the latest authorization code I just asked you to save)
$ mail-& gt; Password? =? sqyofzbqlfkntbncl '; //Set the sender's email address? Fill in the "sender's mailbox" mentioned above here.
$ mail-& gt; From where? =? 12345678 @ QQ . com '; //Is the email body encoded in html? Note that this is a method. No longer an attribute? Right or wrong
$ mail-& gt; isHTML(true); ?
//Set the recipient's mailbox? This method has two parameters? The first parameter is the recipient's email address? The second parameter is the nickname set for the address? Different mailbox systems will automatically handle changes? The second parameter here is of little significance.
$ mail-& gt; AddAddress($to, "lsgo online notification"); //Add multiple recipients? Call the method multiple times.
//? $ mail-& gt; Addaddress ('XXX @ 163.com',' lsgo online notification');
//Add a subject for this email.
$ mail-& gt; Theme? =? $ title// Add message body? If the above isHTML set to true, can it be a complete HTML string? For example, use the file_get_contents function to read a local html file.
$ mail-& gt; Body? =? $ content; //Add an attachment to this email? This method also has two parameters? The first parameter is the directory where the attachment is stored (relative directory or absolute directory)? The second parameter is the name of the attachment in the email attachment.
//? $ mail-& gt; addAttachment('。 /d.jpg ',' mm . jpg ');
//Again, this method can be called multiple times? Upload multiple attachments
//? $ mail-& gt; addAttachment('。 /Jlib- 1. 1.0.js ',' Jlib . js ');
$ status? =? $ mail-& gt; send(); //Simple judgment and prompt information
What if ($ status)? {Return? True;
}else{return? Fake;
}
} & lt? phprequire_once("。 /functions . PHP "); $flag? =? SendMail('456789@qq.com',' lsgo Online Notification',' Congratulations on your successful joining LSGO Lab and starting your learning journey!' ); if($flag){echo? "The mail was sent successfully!" ;
}else{echo? "Sending email failed!" ;
}? & gt