我使用Payson支付网关,在完成付款后,当用户被重定向回感谢页面时,会向用户发送两封相同的电子邮件。请帮我解决这个问题。代码如下:
$select="select * from #__content where id=12 and state=1";
$db->setQuery($select);
$result = $db->loadObject();
echo $result->introtext;
//echo $_REQUEST['id'];
$select = "select * from #__booking order by id desc";
$db->setQuery($select);
$db->query();
$id=$db->loadObject();
$insert_id=$id->id;
$printid=base64_encode($insert_id);
$db=& JFactory::getDBO();
$select_brand="select * from #__booking where id=".$id->id."";
$db->setQuery($select_brand);
$result = $db->loadObject();
$db=& JFactory::getDBO();
$select_brand="select * from #__brand where published=1 and id=".$result->brand."";
$db->setQuery($select_brand);
$result_brand = $db->loadObject();
$select_model="select * from #__modno where published=1 and id=".$result->model."";
$db->setQuery($select_model);
$result_model = $db->loadObject();
$printlink=JURI::root()."print.php?id=".$insert_id;
$link="http://www.status.repair24.se/?id=".$insert_id;
$phoneimagelink=JURI::root()."templates/mobile/images/phicon.png";
$logolink=JURI::root()."templates/mobile/images/2.png";
$to= $result->email;
$subject = "Invoice Mail";
$body.='<center><div style="width:100%;background-color:#f1f3f6;"><br>
<table bgcolor="#dde1e8" cellpadding="10" width="70%" style="border:1px solid #000;">
<tr><td>
<table bgcolor="white" align="center" cellpadding="5" cellspacing="5" width="100%" style="border:1px solid #000;">
<tr>
<td>
<table width="100%">
<tr>
<td align="left"><img src="'.$logolink.'" width="200"></td>
<td align="right"><img src="'.$phoneimagelink.'" style="margin:3px 5px -3px 0" alt="" border="0">123456789</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Name : '.$result->name.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Address: '.$result->address.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Zip Code: '.$result->zip.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Mobile : '.$result->mobile.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Email : '.$result->email.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Brand : '.$result_brand->name.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Model: '.$result_model->name.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Size '.$result->size.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Imei : '.$result->imei.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Operator : '.$result->operator.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Lock CODE : '.$result->lockcode.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Error Descriptions : '.rtrim($result->repairs,',').'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Price : '.$result->price.' SEK
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
Repair Number : '.$result->num.'
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
<a href='.$printlink.'>Click here </a>to print Your Booking Details.
</td>
</tr>
<tr>
<td style="font-size:12px;font-family:Arial;" align="left">
<a href='.$link.'>Click here </a>to check status.
</td>
</tr>
</table></td></tr></table><br><br></div></center>';
// To send HTML mail, the Content-type header must be set
$from = array("info@repair24.se", "Repair 24");
// To send HTML mail, the Content-type header must be set
# Invoke JMail Class
$mailer = JFactory::getMailer();
# Set sender array so that my name will show up neatly in your inbox
$mailer->setSender($from);
# Add a recipient -- this can be a single address (string) or an array of addresses
$mailer->addRecipient($to);
$mailer->setSubject($subject);
$mailer->setBody($body);
# If you would like to send as HTML, include this line; otherwise, leave it out
$mailer->isHTML(1);
# Send once you have set all of your options
$ma=$mailer->send();
答案 0 :(得分:0)
..我遇到类似代码的相同问题(在Joomla 2.5上)!
我还可以补充说,有些电子邮件地址总是单独收到,而其他电子邮件地址总是作为双胞胎收到。在我看来,由于代码与接收者有关,或与发送者(在这种情况下为SendMail)和接收者有关的混合问题,这不是问题。
感谢您的任何建议或诊断指示。
祝福,
胭脂红
..我自己解决了,在这里我提出问题和解决方案,以便它可以帮助别人:
我有这段代码,用HTML内容发送电子邮件:
$mailing_list = & JFactory::getMailer ();
for ($i = 0; $i < count ($recipients_mailing_list); $i++) {
if (substr_count ($recipients_mailing_list[$i], '@')) {
$sent_ok = $mailing_list->sendMail ('info@my_domain', 'my_domain', $recipients_mailing_list[$i], $email_ref, htmlspecialchars_decode ($email_body), TRUE);
}
}
..并且它处理了发送,以便处理的任何新收件人也会再次发送前一个收件人。 即:如果我有3个收件人,第一个接收电子邮件3次,第二个收到两次,最后一个收到一封电子邮件。
我解决了将声明JFactory :: getMailer()移动到for循环中以便更新“实例构造”并清理它,如下所示:
for ($i = 0; $i < count ($recipients_mailing_list); $i++) {
if (substr_count ($recipients_mailing_list[$i], '@')) {
$mailing_list = & JFactory::getMailer ();
$sent_ok = $mailing_list->sendMail ('info@my_domain', 'my_domain', $recipients_mailing_list[$i], $email_ref, htmlspecialchars_decode ($email_body), TRUE);
}
}
在代码方面效率不高,但它可以正常工作。
有没有更好的方法来解决它?
感谢您的任何建议。
祝福,
胭脂红
答案 1 :(得分:0)
Joomla 2.5 Mail功能如下。
成功时返回 true 或 JError对象。所以,你的情况应该如下。
$ send =&amp; $ mailer-&gt;置于();
if($ send!== true){
echo 'Error sending email: ' . $send->message;
}其他{
echo 'Mail sent';
}
您将使用以下链接查看有关joomla文档的更多详细信息。 http://docs.joomla.org/Sending_email_from_extensions
希望此解决方案适合您。