【问题标题】:Magento adding BCC is not workingMagento 添加密件抄送不起作用
【发布时间】:2014-04-28 02:02:48
【问题描述】:

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

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

【问题讨论】:

    标签: magento email bcc


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      我认为你在这里犯了错误

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

      希望你能得到输出。

      【讨论】:

      • 你说得对,这行得通,但我上面的解决方案也行得通,但我宁愿在不需要时不使用循环:)
      猜你喜欢
      • 2012-09-13
      • 2023-03-20
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 2014-02-08
      • 2014-10-28
      • 2014-07-16
      • 1970-01-01
      相关资源
      最近更新 更多