1

嗨,我写了下面的代码,它将发送一封电子邮件,一切正常,除了它不发送密件抄送外,我不确定是什么导致它不添加密件抄送。任何帮助表示赞赏。

 public function sendFraudEmail($observer)
    {
    /* @var $mailTemplate Mage_Core_Model_Email_Template */
    $mailTemplate = Mage::getModel('core/email_template');
    $template = Mage::getStoreConfig('sales_email/order/template', Mage::app()->getStore()->getId());
    $template_collection =  $mailTemplate->load($template);
    $template_data = $template_collection->getData();
    $templateId =  Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE);
    $mailSubject = $template_data['template_subject'];
    $sender  = array(
        'name' => Mage::getStoreConfig('trans_email/ident_support/name', Mage::app()->getStore()->getId()),
        'email' => Mage::getStoreConfig('trans_email/ident_support/email', Mage::app()->getStore()->getId()));
    $obj = $mailTemplate->setReplyTo($sender['email'])->setTemplateSubject($mailSubject);
    $vars = NULL;
    $order = $observer->getEvent()->getOrder();
    $storeId          = $order->getStoreId();
    $IncrementId = $order->getIncrementId();
    $status = $order->getStatus();
    $customer_name = $order->getCustomerName();
    $customer_email = $order->getCustomerEmail();
     /*ADD BCC*/
    $copyTo = explode(",",Mage::getStoreConfig(self::XML_PATH_EMAIL_BCC));
    if (!empty($copyTo) && isset($copyTo)) {
        // Add bcc to customer email
        foreach ($copyTo as $bccemail) {
            $mailTemplate->addBcc($bccemail);
        }
    }try{
        $obj->sendTransactional($templateId, $sender, $customer_email,customer_name, $vars, $storeId);
    } catch (exception $e){
        Mage::log("something went wrong.." . $e->getMessage());
    }
4

2 回答 2

1

我实际上曾经遇到过类似的问题。据我了解,使用密件抄送时,您需要将信息发送到电子邮件标头。这是我的类似代码的副本,其中包含对我遇到的问题的评论:

    // Get the destination email addresses to send copies to
    $copyTo = $this->_getEmails(self::XML_PATH_EMAIL_COPY_TO);

    // Retrieve corresponding email template id and customer name
    $templateId = Mage::getStoreConfig($emailTemplate);
    $mailer = Mage::getModel('core/email_template_mailer');

    //Set it to send it to the user.
    $emailInfo = Mage::getModel('core/email_info');
    $emailInfo->addTo($emailTo);
    $mailer->addEmailInfo($emailInfo);

    if ($copyTo) {
        foreach ($copyTo as $email) {
            $emailInfo = Mage::getModel('core/email_info');
//                *Just* using add Bcc throws an exception which asks for a "To" field.      Because all the emails are
//                sent separately (not one mass email), To, CC, and BCC are all essentially the same thing
//                If for some reason you need CC or BCC, you will likely need to set something to the To header.
//                $emailInfo->addBcc($email);
            $emailInfo->addTo($email);
            $mailer->addEmailInfo($emailInfo);
        }
    }
于 2014-03-21T21:45:34.750 回答
0

我认为你在这里犯了错误

  $copyTo = explode(",",Mage::getStoreConfig(self::XML_PATH_EMAIL_BCC)); 

  if (!empty($copyTo) && isset($copyTo)) { 
      // Add bcc to customer email 
       foreach ($copyTo as $bccemail) {  
            $mailTemplate->addBcc($bccemail); 
  }

$copyTo返回一个数组值。你可以不加foreach.

所以你需要像这样更改代码。

 if (!empty($copyTo) && isset($copyTo)) { 
      // Add bcc to customer email 
            $mailTemplate->addBcc($copyTo);
  }

希望你能得到输出。

于 2014-03-21T04:23:24.843 回答