The first step:

Open the https://github.com/PHPMailer/PHPMailer/ download PHPMailer, PHPMailer need PHP sockets extension support, while login QQ email SMTP server must through SSL encryption, PHP must also include OpenSSL support.

Step 2: Use the phpInfo () function to view socket and OpenSSL extensions (which are enabled by default on WAMP Server).

If openssl is not enabled, open the php.ini file to enable openssl

First check php.ini; Extension =php_openssl. DLL if extension=php_openssl. DLL ‘, if this line does not exist, then add extension= php_openSSL.dll.

PHPMailer core files

Step 3: SET up QQ mailbox

All mainstream mailboxes support THE SMTP protocol. However, not all mailboxes are enabled by default. You can manually enable the SMTP protocol in the mailbox Settings.

After providing the account and password, the third-party service can log in to the SMTP server to control the mail transfer mode.


Step 4: Enable the SMTP service

Select IMAP/SMTP service and click Enable Service

Step 5: Verify encryption

Send the SMS message “Configure mail client” to 1069-0700-69

Step 6: Obtain the authorization code

SMTP server authentication password, keep it safe (PS: password without space)

Step 7: PHP sends mail

Basic code

The following code demonstrates how to use PHPMailer. Note how to configure an instance of PHPMailer.

PHPMailer's core file require_once()"PHPMailer/class.phpmailer.php");
require_once("PHPMailer/class.smtp.php"); // Instantiate the PHPMailer core class$mail= new PHPMailer(); // Whether to enable the DEBUGGING function of SMTP. Development environment You are advised to enable the debugging function in the production environment$mail->SMTPDebug = 1; // Use SMTP authentication to send emails$mail->isSMTP(); // SMTP requires authentication this must betrue
$mail->SMTPAuth = true; // Link qq domain mail server address$mail->Host = 'smtp.qq.com'; // Set SSL encryption for login authentication$mail->SMTPSecure = 'ssl'; // Set the port number of the remote server for the SSL connection to the SMTP server$mail->Port = 465; // Set the code of the message to be sent$mail->CharSet = 'UTF-8'; // Set sender nickname The sender name displayed next to the sender email address of the recipient's mail$mail->FromName = 'Sender nickname'; // SMTP login account QQ email is ok$mail->Username = '[email protected]'; // The SMTP login password uses the generated authorization code$mail->Password = '* * * * * * * * * *'; // Set the sender email address and login account$mail->From = '[email protected]'; // Whether the message body is HTML-encoded note that this is a method$mail->isHTML(true); // Set the recipient email address$mail->addAddress('[email protected]'); // To add multiple recipients, call the method multiple times$mail->addAddress('[email protected]'); // Add the subject of the message$mail->Subject = 'Email subject'; // Add the message body$mail->Body = '<h1>Hello World</h1>'; // Add an attachment to the message$mail->addAttachment('./example.pdf'); // Sending an email returns the status$status = $mail->send();Copy the code