The previous mail () is no longer popular, so I put the recently used instances for memories. For more information, see
The previous mail () is no longer popular, so I put the recently used instances for memories. For more information, see
The previous mail () is no longer popular, so we put the latest instances for memories.
The Code is as follows:
Require_once (dirname (_ FILE _). "/../phpmailer/class. phpmailer. php ");
// Contains class. phpmailer. php
/**
* @ Param string $ send_to_mail target email
* @ Param stinrg $ subject topic
* @ Param string $ body content
* @ Param string $ extra_hdrs Additional information
* @ Param string $ username recipient
* @ Param string $ replyname reply
* @ Param string $ replymail reply address
* @ Return array (bealoon, string) the returned array contains two elements. bealoon indicates whether the operation is successful. string indicates the prompt information.
*/
Function SendMail ($ send_to_mail, $ subject, $ body, $ extra_hdrs, $ username, $ replyname = "reply", $ replymail = "reply@reply.com "){
$ Mail = new PHPMailer ();
$ Mail-> IsSMTP (); // mail sending Method
$ Mail-> Host = "smtp.host.com"; // SMTP server Host address
$ Mail-> SMTPAuth = true; // whether it is a trusted SMTP
$ Mail-> Username = "reply@reply.com"; // SMTP User Name Note: normal mail authentication does not need to add @ Domain Name
$ Mail-> Password = "******"; // SMTP User Password
$ Mail-> From = "send@send.com"; // the sender's email address
$ Mail-> FromName = "send"; // sender
$ Mail-> CharSet = "GB2312"; // specify the character set
$ Mail-> Encoding = "base64 ";
$ Mail-> AddAddress ($ send_to_mail, $ username); // Add the target sending Address
$ Mail-> AddReplyTo ($ replymail, $ replyname); // Add a reply address
$ Mail-> IsHTML (true); // The mail type is in HTML format.
$ Mail-> Subject = $ subject; // mail Subject
// Email content
$ Mail-> Body ="
". $ Body ."
";
$ 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 ();
?>
The Code is as follows:
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 ='
Test content |
This is content |
';
$ Address = '1970 @ 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! ";
}