我不知道如何在以下编码中添加cc或bcc ..我试过bcc但邮件不能去。请一些帮助!..
代码是
$data = array('name' => $username, 'to_user_id' => $to_userid, 'email' => $email, 'telephone' => $telephone, 'title' => $title, 'ip' => $ip, 'message' => $message);
$templateId =1;
$sender = Array('name' => "Admin", 'email' => "webmaster@example.com");
$useremail = $product_user;
$emailName = $username;
$vars = array('username' => $username, 'telephone' => $telephone, 'mail_id' => $email, 'title' => $title, 'message' => $message, 'object' => $this);
$storeId = Mage::app()->getStore()->getId();
$mailSubject = 'mail check';
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
Mage::getModel('core/email_template')
->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
->setTemplateSubject($mailSubject)
->setBcc('zzz@gmail.com')
->sendTransactional($templateId, $sender, $useremail, $emailName, $vars, $storeId);
$translate->setTranslateInline(true);
$model = Mage::getModel("contacts/contacts")->setData($data)->save();
Mage::getSingleton("core/session")->addSuccess("You have been successfully sent your mail..");
$this->_redirectReferer();
return;
答案 0 :(得分:5)
您可以在代码中使用addBcc('zzz@gmail.com')
代替setBcc('zzz@gmail.com')
,也可以像这样修改代码
//mail transaction
$mail = Mage::getModel('core/email_template');
$mail->getMail()->addCc('zzz@gmail.com');
$mail->addBcc('zzz@gmail.com')
->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
->setTemplateSubject($mailSubject)
->sendTransactional($templateId, $sender, $useremail, $emailName, $vars, $storeId);
答案 1 :(得分:3)
Mage_Core_Model_Email class
不支持bcc(或cc)。您需要覆盖send方法并在$mail->send();
之前添加此代码。
if ($this->getBcc()) {
$mail->addBcc($this->getBcc());
}
之后你的代码可以是:
$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($customerEmail)
->setBody($processedTemplate)
->setSubject('Subject')
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html')
->setBcc('test@example.com') //bcc line added
->send();
答案 2 :(得分:0)
将密件抄送添加到Magento与我们联系。
转到“管理面板”->“系统”->“配置”->“联系人”。您可以在“电子邮件选项”部分中看到“将电子邮件发送到”。现在,如果要将“发送电子邮件密件抄送”添加到此部分。
从app / code / core / Mage / Contacts复制联系人扩展文件夹以粘贴app / code / local / Mage / Contacts。
打开app / etc / modules / Mage_All.xml(转到第360行),将代码池核心更改为本地。
<Mage_Contacts>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Core/>
</depends>
</Mage_Contacts>
打开app / code / local / Mage / Contacts / etc / system.xml,并找到以下代码(第67行)
<recipient_email translate="label">
<label>Send Emails To</label>
<frontend_type>text</frontend_type>
<validate>validate-email required-entry</validate>
<sort_order>10</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</recipient_email>
在system.xml中的上述代码之后添加以下代码
<recipient_email2 translate="label">
<label>Send Emails BCC</label>
<frontend_type>text</frontend_type>
<sort_order>11</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</recipient_email2>
打开app / code / local / Mage / Contacts / controllers / IndexController.php(转到第37行),添加以下代码。
const XML_PATH_EMAIL_RECIPIENT2 = 'contacts/email/recipient_email2';
然后转到第94行并找到以下代码。
$mailTemplate = Mage::getModel('core/email_template');
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
然后替换为以下代码:
$bcc_str = Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT2);
$bcc_email = explode(",", $bcc_str);
$mailTemplate = Mage::getModel('core/email_template');
/* @var $mailTemplate Mage_Core_Model_Email_Template */
$mailTemplate->addBcc($bcc_email)
->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject));