Use PHPMailer to send Gmail account emails_PHP tutorial

WBOY
Release: 2016-07-13 17:45:51
Original
1202 people have browsed it

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 = "
                                                                                                                                                                                                                                                                          '.$body.'";
$mail->AltBody = "text/html";
If (! $mail->Send ()) {
//Email sending failed
        return false;
} else {
//Email sent successfully
        return true;
}  

} //function end

Author "butter"

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478633.htmlTechArticleThe 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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template