Use PHPMAILER to send the mail instance application
- 2020-05-26 08:08:42
- OfStack
mail(), as it used to be, is no longer in fashion, so put the most recent example in memory.
<?php
require_once(dirname(__FILE__)."/../phpmailer/class.phpmailer.php");
// contains class.phpmailer.php
/**
* @param string $send_to_mail Target email
* @param stinrg $subject The theme
* @param string $body Email content
* @param string $extra_hdrs Additional information
* @param string $username The recipient
* @param string $replyname Respond to people
* @param string $replymail The return address
* @return array(bealoon,string) The return array contains two elements, bealoon Is it successful or not, string For prompt information
*/
function SendMail($send_to_mail,$subject,$body,$extra_hdrs,$username,$replyname="reply",$replymail="reply@reply.com"){
$mail=new PHPMailer();
$mail->IsSMTP(); // Email mode
$mail->Host="smtp.host.com"; //SMTP Server host address
$mail->SMTPAuth=true; // Whether or not it is trustworthy SMTP
$mail->Username="reply@reply.com"; //SMTP The user name Note: regular mail authentication is not required @ The domain name
$mail->Password="******"; //SMTP The user password
$mail->From="send@send.com"; // Sender email address
$mail->FromName="send"; // The sender
$mail->CharSet="GB2312"; // Specified character set
$mail->Encoding="base64";
$mail->AddAddress($send_to_mail,$username); // Add the send target address
$mail->AddReplyTo($replymail,$replyname); // Add reply address
$mail->IsHTML(true); // The email type is HTML format
$mail->Subject=$subject; // Email subject
// Email content
$mail->Body="<html><head>
<meta http-equiv='Content-Language' content='zh-cn'>
<meta http-equiv='Content-Type' content='text/html; charset=GB2312'></head>
<body>
".$body."
</body>
</html>";
$mail->AltBody="text/html"; // Content text format
if (@!$mail->Send()) {
$results=array("result"=>false,"message"=>$mail->ErrorInfo);
return $results;
}else{
$results = array("result"=>true,"message"=>" The email 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();
?>
<?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> The test content </td></tr><tr><td> This is the content </td></tr></table>';
$address='379018082@qq.com';
$username=' I am ';
$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! ";
}