sendTransactional()
在调用函数期间我也遇到了同样的错误。我在想主题中的电子邮件模板存在一些问题。为了找到 Jurgen Thalen 在他的回答中提到的确切问题,我检查了Mage_Core_Model_Email_Template::isValidForSend()
如下功能
public function isValidForSend()
{
//remove this after checking, never change core files
Mage::log("Sender Name:".$this->getSenderName());
Mage::log("Sender email:".$this->getSenderEmail());
Mage::log("Template subject:".$this->getTemplateSubject());
Mage::log("Email disabled:".Mage::getStoreConfigFlag('system/smtp/disable'));
return !Mage::getStoreConfigFlag('system/smtp/disable')
&& $this->getSenderName()
&& $this->getSenderEmail()
&& $this->getTemplateSubject();
}
现在检查您的system.log
for me 模板主题是否正常,但发件人姓名和发件人电子邮件未出现。
下面是我的代码:
sendTransactional(
$template,
"myemail@gmail.com",
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
)
以下是核心文件中的发送交易功能:
/**
* Send transactional email to recipient
*
* @param int $templateId
* @param string|array $sender sneder informatio, can be declared as part of config path
* @param string $email recipient email
* @param string $name recipient name
* @param array $vars varianles which can be used in template
* @param int|null $storeId
* @return Mage_Core_Model_Email_Template
*/
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
如您所见,第二个参数 $sender 应该是字符串或数组,因为我正在传递字符串但不接受。
我改变了我的sendTransactional()
喜欢如下:第二个参数作为数组传递
sendTransactional(
$template,
array(
'email' => "myemail@gmail.com",
'name' => "satish sojitra",
),
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
)
它就像魅力一样!不要忘记Mage::log
从核心文件中删除语句。
以下是发送交易电子邮件的完整代码片段
$translate = Mage::getSingleton('core/translate');
//@var $translate Mage_Core_Model_Translate
$translate->setTranslateInline(false);
$mailTemplate = Mage::getModel('core/email_template');
//add bcc
$mailTemplate->addBcc("bccemail@gmail.com");//accept array also
//add cc: $Cc_email_ids can be array or string
$mailTemplate->getMail()->addCc($Cc_email_ids);//accept array also
/* @var $mailTemplate Mage_Core_Model_Email_Template */
//template path
$templateConfigPath = "configuration/product_settings/failure_template";
$template = Mage::getStoreConfig($templateConfigPath, Mage::app()->getStore()->getId());
$to = array(
array("email"=> "to_1@gmail.com","name"=>"to_name"),
array("email"=> "to_2@gmail.com","name"=>"to_name")
);
$sendTo = array();
foreach ($to as $recipient)
{
if (is_array($recipient))
{
$sendTo[] = $recipient;
}
else
{
$sendTo[] = array(
'email' => $recipient,
'name' => null,
);
}
}
$myvar1 = 0;
$myvar2 = 0;
$myvar3 = 0;
$myvar4 = "transactional email testing";
foreach ($sendTo as $recipient) {
$mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>Mage::app()->getStore()->getId()))
->sendTransactional(
$template,
array(
'email' => "myemail@gmail.com",
'name' => "satish sojitra",
),
$recipient['email'],
$recipient['name'],
array(
'myvar1' => $myvar1,
'myvar2' => $myvar2,
'myvar3' =>$myvar3,
'myvar4' =>$myvar4
)
);
}
$translate->setTranslateInline(true);
我希望这会对某人有所帮助。