The previous mail (), has not been popular, so put on the recent example, to stay for memory.
Copy Code code as follows:
<?php
Require_once (DirName (__file__). " /.. /phpmailer/class.phpmailer.php ");
Contains class.phpmailer.php
/**
* @param string $send _to_mail destination Message
* @param stinrg $subject Themes
* @param string $body message contents
* @param string $extra _hdrs additional information
* @param string $username recipient
* @param string $replyname reply person
* @param string $replymail reply address
* @return Array (bealoon,string) to return arrays include two elements, Bealoon indicates success, string is a hint
*/
function SendMail ($send _to_mail, $subject, $body, $extra _hdrs, $username, $replyname = "Reply", $replymail = " Reply@reply.com ") {
$mail =new Phpmailer ();
$mail->issmtp (); How messages are Sent
$mail->host= "smtp.host.com"; SMTP Server host Address
$mail->smtpauth=true; Whether to be a trusted SMTP
$mail->username= "reply@reply.com"; SMTP User name Note: Normal mail authentication does not require @ domain name
$mail->password= "Hu Jintao"; SMTP User Password
$mail->from= "send@send.com"; Sender mail Address
$mail->fromname= "Send"; Sender
$mail->charset= "GB2312"; Specify character Set
$mail->encoding= "base64";
$mail->addaddress ($send _to_mail, $username); Add Send Destination Address
$mail->addreplyto ($replymail, $replyname); Add a Reply address
$mail->ishtml (TRUE); Message type is HTML format
$mail->subject= $subject; Message subject
Message content
$mail->body= "<meta http-equiv= ' content-language ' content= ' ZH-CN ' >
<meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' ><body>
". $body."
</body>
$mail->altbody= "text/html"; Content text formatting
if (@! $mail->send ()) {
$results =array ("Result" =>false, "message" => $mail->errorinfo);
return $results;
}else{
$results = Array ("Result" =>true, the message "=>" Mail has been sent to {$send _to_mail}! ");
return $results;
}
}
$send _mail=sendmail ($to, $subject, $content, $headers, $name);
if ($send _mail["Result"]) {
echo $send _mail["message"];
}else{
echo $send _mail["message"];
}
Exit ();
?>
Copy Code code as follows:
<?php
Include (' class/class.phpmailer.php ');
$config = Array (
' Host ' => ' smtp.163.com ',
' Port ' => ' 25 ',
' User ' => ' * * *,
' passwd ' => ' * * * *,
' From ' => ' juva_zz@163.com ',
' FromName ' => ' Zhengzhou ',
);
$subject = ' This is a test mail ';
$body = ' <table style= background: #dfdfdf ' ><tr><td> test content </TD></TR><TR><TD > This is Content </td></tr></table> ';
$address = ' 379018082@qq.com ';
$username = ' I ';
$mail = new Phpmailer ();
$mail->charset = ' gb2312 ';
$mail->issmtp ();
$mail->host = $config [' Host '];
$mail->port = $config [' Port '];
$mail->from = $config [' from '];
$mail->fromname = $config [' FromName '];
$mail->smtpauth = true;
$mail->username = $config [' user '];
$mail->password = $config [' passwd '];
$mail->subject= $subject;
$mail->altbody= "text/html";
$mail->msghtml ($body);
$mail->addaddress ($address, $username);
if (! $mail->send ())
{
echo "Mail Error:". $mail->errorinfo;
}else
{
echo "Congratulations on sending success!" ";
}