0

我使用 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();
4

2 回答 2

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);

      }
    }

在代码方面它不是很有效,但它工作正常。

有没有更好的方法来解决它?

感谢您的任何建议。

最好的祝愿,

胭脂红

于 2012-09-05T20:52:35.733 回答
0

Joomla 2.5 邮件功能如下。

它在成功JError 对象时返回true 。所以,你的情况应该如下。

$send =& $mailer->Send();

如果($发送!==真){

echo 'Error sending email: ' . $send->message;

} 别的 {

echo 'Mail sent';

}

您将使用以下链接查看有关 joomla 文档的更多详细信息。 http://docs.joomla.org/Sending_email_from_extensions

希望此解决方案对您有用。

于 2013-03-07T09:57:04.693 回答