Use PHPMailer to send emails with the Gmail account. The detailed code is as follows: Php code defines a function for sending emails, which has passed the test. $ Sendto_email: email sending address $ subject: Email subject $ body: the detailed code of the email body is as follows:
Php code
// The following defines a function for sending emails, which has passed the test.
// $ Sendto_email: email sending address
// $ Subject: email subject
// $ Body: body of the email
// $ Sendto_name indicates the sender's name. It is generally saved.
Function stmp_mail ($ sendto_email, $ subject = null, $ body = null, $ sendto_name = null ){
Vendor ("PHPMailer. class # phpmailer"); // class of the function package imported. phpmailer. php
$ Mail = new PHPMailer (); // creates a 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, which must be replaced with the mail server address where the email is sent, SMTP settings of gmail are used here
$ Mail-> SMTPAuth = true; // turn on SMTP authentication
$ Mail-> Username = "leobrilliantlife@gmail.com"; // The user name of this mailbox on the SMTP server, some only need to @ the front part, and some need the full name. Replace it with the correct email user name
$ Mail-> Password = "*****"; // replace the Password of the mailbox on the SMTP server with the correct Password.
$ Mail-> From = "leobrilliantlife@gmail.com"; // The mailbox that sent this email on the SMTP server, replace it with the correct one, and the value of $ mail-> Username corresponds.
$ Mail-> FromName = "handheld Shunde"; // enter the real sender's name and other information as needed.
$ Mail-> CharSet = "UTF-8"; // The character set is specified here!
$ Mail-> Encoding = "base64 ";
$ Mail-> AddAddress ($ sendto_email, $ sendto_name); // recipient's email address 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"); // process attachments
// $ Mail-> AddAttachment ("/tmp/image.jpg", "new.jpg ");
$ Mail-> IsHTML (true); // send as HTML
$ Mail-> Subject = $ subject; // mail Subject
// Email content
$ Mail-> Body ="
'. $ Body .'";
$ Mail-> AltBody = "text/html ";
If (! $ Mail-> Send ()){
// Email sending failed
Return false;
} Else {
// The email is sent successfully.
Return true;
}
} // Function end
Author "butter"
Php code // The following defines a function for sending emails, which has passed the test. // $ Sendto_email: email sending address // $ subject: email subject // $ body: body content...