Use Phpmailer to send Gmail account email _php Tutorials

Source: Internet
Author: User
Tags word wrap
The detailed code is as follows


PHP code
The following defines a function that sends a message that has been tested.
$sendto _email: Mail send address
$subject: Message subject
$body: Message body Content
$sendto _name The name of the recipient of the message and the sender. Generally can be saved.
function Stmp_mail ($sendto _email, $subject = null, $body = NULL, $sendto _name = null) {

Vendor ("Phpmailer.class#phpmailer"); Class class.phpmailer.php for importing function packages


$mail = new Phpmailer (); Create a new mail-sending class object
$mail->issmtp (); Send via SMTP
$mail->port = 25; Send Port
$mail->host = "ssl://smtp.gmail.com:465"; SMTP mail server address, where you need to replace the mail server address of the mailbox where the message was sent, using Gmail's SMTP settings
$mail->smtpauth = true; Turn on SMTP authentication mail server Authentication on
$mail->username = "leobrilliantlife@gmail.com"; The user name of this mailbox on the SMTP server requires only the previous part of the @, and some require a full name. Please replace the correct mailbox user name
$mail->password = "* * *"; Password for the mailbox on the SMTP server, replace with the correct password
$mail->from = "leobrilliantlife@gmail.com"; To send this message on the SMTP server, replace the mailbox with the correct mailbox, $mail the->username value is the corresponding one.
$mail->fromname = "Palm Shunde"; Real sender's name and other information, please fill in here as required
$mail->charset = "Utf-8"; Specify the character set here!
$mail->encoding = "base64";
$mail->addaddress ($sendto _email, $sendto _name); Recipient's mailbox and name
$mail->addreplyto (' sdaping@mail.ustc.edu.cn ', ' Administrator ');//This one is based on the need
$mail->wordwrap = 50; Set word Wrap
$mail->addattachment ("/var/tmp/file.tar.gz"); Attachment Handling
$mail->addattachment ("/tmp/image.jpg", "new.jpg");
$mail->ishtml (TRUE); Send As HTML
$mail->subject = $subject; Message subject
Message content
$mail->body = "


'. $body. '";
$mail->altbody = "text/html";
if (! $mail->send ()) {
Message failed to send
return false;
} else {
Message sent successfully
return true;
}

}//function End

Author "Butter"

http://www.bkjia.com/PHPjc/478633.html www.bkjia.com true http://www.bkjia.com/PHPjc/478633.html techarticle the detailed code is as follows PHP code//The following defines a Send mail function, has been tested pass. $sendto _email: Email address//$subject: Message subject//$body: Message body content ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.