Use PHPMAILER to send an email to an app _ php instance

Source: Internet
Author: User
The previous mail () is no longer popular, so I put the recently used instances for memories. if you need a friend, you can refer to the previous mail (), which is no longer popular, so put the latest instance 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! ";
}

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.