Use Phpmailer to send mail instance to apply _php instance

Source: Internet
Author: User
Tags character set
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 &LT;/TD&GT;&LT;/TR&GT;&LT;TR&GT;&LT;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!" ";
}

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.