The detailed code is as follows
Php code
//The following defines a function for sending emails, which has been tested.
//$sendto_email: Email sending address
//$subject: Email subject
//$body: Email body content
//$sendto_nameThe name of the email recipient and the name given by the sender. Generally can be saved.
function stmp_mail($sendto_email, $subject = null, $body = null, $sendto_name = null) {
vendor ( "PHPMailer.class#phpmailer" ); //Import the function package class class.phpmailer.php
$mail = new PHPMailer (); //Create a new mail sending class object
$mail->IsSMTP (); // send via SMTP
$mail->Port = 25; //Sending port
$mail->Host = "ssl://smtp.gmail.com:465"; // SMTP mail server address. This needs to be replaced with the mail server address of the mailbox where the email is sent. The SMTP settings of gmail are used here
$mail->SMTPAuth = true; // turn on SMTP authentication Mail server authentication is on
$mail->Username = "leobrilliantlife@gmail.com"; // The username of this mailbox on the SMTP server. Some only require the part in front of @, and some require the full name. Please replace it with the correct email username
$mail->Password = "****"; // The password for the email on the SMTP server, please replace it with the correct password
$mail->From = "leobrilliantlife@gmail.com"; // The email address on the SMTP server that sent this email. Please replace it with the correct email address. The value of $mail->Username is corresponding.
$mail->FromName = "Shunde"; // The name of the real sender and other information, fill in here as needed
$mail->CharSet = "utf-8"; // Specify the character set here!
$mail->Encoding = "base64";
$mail->AddAddress ($sendto_email, $sendto_name); // Recipient email and name
//$mail->AddReplyTo('sdaping@mail.ustc.edu.cn',"Administrator");//This item is set as needed
//$mail->WordWrap = 50; // set word wrap
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // Attachment processing
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML (true); // send as HTML
$mail->Subject = $subject; // Email subject
// Email content
$mail->Body = "