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 ...