Magento添加BCC不起作用
您好,我写了下面的代码,将发送电子邮件,一切工作,除了它不发送密件抄送出去,我不知道是什么原因导致它不添加密件抄送。感谢您的帮助Magento添加BCC不起作用,magento,email,bcc,Magento,Email,Bcc,您好,我写了下面的代码,将发送电子邮件,一切工作,除了它不发送密件抄送出去,我不知道是什么原因导致它不添加密件抄送。感谢您的帮助 public function sendFraudEmail($observer) { /* @var $mailTemplate Mage_Core_Model_Email_Template */ $mailTemplate = Mage::getModel('core/email_template'); $template = M
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());
}
我认为你犯了错误
$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);
}
希望你能得到输出 我曾经遇到过类似的问题。据我所知,使用密件抄送时,您需要将信息发送到电子邮件标题。下面是我的类似代码的副本,以及我遇到的问题的评论:
// 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);
}
}
你是对的,这是可行的,但我上面的解决方案也有效,但我宁愿在不需要时不使用循环:)