使用PHPmailer时两次添加“收件人"地址 [英] 'To' address being added twice while using PHPmailer
本文介绍了使用PHPmailer时两次添加“收件人"地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PHPmailer发送邮件.但是,该邮件被发送给每个用户两次.以下是测试邮件的屏幕截图.
I am using PHPmailer to send mails. However, the mail is being sent to each user twice. Below is the screen-shot of a test mail.
以下是我的代码:
<?php
##REQUIRED FUNCTION
function send_mail_to($receiver, $msg)
{
$subject="[ TNP Update ] - Do you like the new look ?";
#Grab the PHPmailer class
require_once('./lib/phpmailer/phpmailer.inc.php');
#Create object
$mailer = new PHPmailer(); //Instantiate class
$mailer->From="tnp@aakashbhowmick.in";
$mailer->FromName="TNP Mailer";
$mailer->IsHTML(true);
$mailer->Subject = $subject;
$mailer->Body = $msg;
$mailer->AddAddress($receiver);
#Send the email
set_time_limit(300);
$mailer->Send();
} //End of send_mail_to()
###### THE WORKING CODE ######
#Only authorised access is allowed.
if($_POST['signature']=="some-secret-signature-here"){
$msg1=urldecode($_POST['text']);
# Formatting the message a little
$msg1=str_replace("#c0c0c0","#EAE99A",$msg1);
$msg1=str_replace("<td","<td style='font-family:Trebuchet MS,Verdana,arial'; ",$msg1);
#Start sending mails. Some lines commented for testing purpose
//include("connection.php");
//$result=mysql_query("SELECT * FROM subscribers");
$subscriber=array('id'=>'1','email'=>'aakashrocks@gmail.com','active'=>'1');
//while($subscriber=mysql_fetch_array($result)){
if($subscriber['active']==1){
$body="Some text";
send_mail_to($subscriber['email'], $body);
} #End-of-if
//} #End-of-while
} ##End of if
?>
推荐答案
我遇到了同样的问题,对我而言,解决方案是更改
I had the same problem, for me solution was to change
$mailer->isSMTP();
到
$mailer->Mailer = 'smtp';
因此,请尝试使用$mailer->Mailer
.
这篇关于使用PHPmailer时两次添加“收件人"地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文