Home  >  Article  >  Backend Development  >  Example application of sending emails using PHPMAILER_PHP tutorial

Example application of sending emails using PHPMAILER_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:15:10758browse

The old mail() is no longer popular, so I will put the most recently used examples as memories. " /../phpmailer/class.phpmailer.php");

//Contains class.phpmailer.php

/*** @param string $send_to_mail target email* @param stinrg $subject subject* @param string $body email content* @param string $extra_hdrs additional information
* @param string $username Recipient
* @param string $replyname Replyer
* @param string $replymail Reply address
* @return array(bealoon,string) The returned array includes two elements, and bealoon indicates whether it was successful or not. , string is the prompt information
*/
function SendMail($send_to_mail,$subject ,$body,$extra_hdrs,$username,$replyname="reply",$replymail="reply@reply.com"){
$mail=new PHPMailer();
$mail->IsSMTP( ); //Email sending method
$mail->Host="smtp.host.com"; //SMTP server host address
$mail->SMTPAuth=true; //Whether it is trusted SMTP
$mail->Username="reply@reply.com"; //SMTP username Note: Ordinary email authentication does not require adding @domain name
$mail->Password="***** *"; //SMTP user password
$mail->From="send@send.com"; //Sender's email address
$mail->FromName="send"; //Send To
$mail->CharSet="GB2312"; //Specify character set
$mail->Encoding="base64";
$mail->AddAddress($send_to_mail,$username ); //Add destination address
$mail->AddReplyTo($replymail,$replyname); //Add reply address
$mail->IsHTML(true); //Email type is HTML format
$mail->Subject=$subject; //Email 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();
?>






Copy code

The code is 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">Test contentThis is the content';
$address='379018082@qq.com';
$username='me';

$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 successfully! ";
}





http://www.bkjia.com/PHPjc/326136.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/326136.html
TechArticle

The old mail() is no longer popular, so I will put the most recently used examples as memories. Copy the code The code is as follows: ?php require_once(dirname(__FILE__)."/../phpmailer/class.phpmailer...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn