您好我以编程方式在magento中添加邮件。默认邮件系统运行良好。但我的邮件是通过这个错误。
2013-10-08T05:06:17+00:00 ERR (3):
exception 'Exception' with message 'This letter cannot be sent.' in /home/domain/public_html/fashion/app/code/core/Mage/Core/Model/Email/Template.php:398
Stack trace:
#0 /home/mall140/public_html/fashion/app/code/local/seller/Marketplaceseller/controllers/SendmailController.php(18): Mage_Core_Model_Email_Template->send('amia.1901@...', 'victor', Array)
#1 /home/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Webkul_Marketplacepartner_SendmailController->indexAction()
#2 /home/fashion/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#3 /home/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 /home/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#5 /home/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#6 /home/index.php(87): Mage::run('', 'store')
这是错误代码。请帮帮我
答案 0 :(得分:5)
此异常表示Mage_Core_Model_Email_Template::isValidForSend()
已返回false
:
public function isValidForSend()
{
return !Mage::getStoreConfigFlag('system/smtp/disable')
&& $this->getSenderName()
&& $this->getSenderEmail()
&& $this->getTemplateSubject();
}
在发送之前没有看到设置电子邮件模板的代码,很难说这四个条件中的哪一个失败了。
我的猜测是,你的后端会禁用SMTP邮件。
检查System -> Configuration -> System -> Mail sending settings -> Disable Email Communications
是否设置为“否”。
答案 1 :(得分:0)
在调用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
我的模板主题是否正常,但发件人姓名和发件人电子邮件未来。
以下是我的代码:
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应该是String或数组,因为我传递了字符串但是不接受。
我改变了我的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);
我希望这会对某人有所帮助。
答案 2 :(得分:0)
如果您的代码如下所示
$emailTemplate->sendTransactional($emailTemplateId, $sender, $emailAddress, $name, $data, $store);
和Mage_Core_Model_Email_Template :: isValidForSend()返回false。那么最有可能您没有正确传递发件人信息。
检查 app \ code \ core \ Mage \ Core \ Model \ Email \ Template.php
/**
* Send transactional email to recipient
*
* @param int $templateId
* @param string|array $sender sender information, can be declared as part of config path
* @param string $email recipient email
* @param string $name recipient name
* @param array $vars variables which can be used in template
* @param int|null $storeId
*
* @throws Mage_Core_Exception
*
* @return Mage_Core_Model_Email_Template
*/
public function sendTransactional($templateId, $sender, $email, $name, $vars=array(), $storeId=null)
将发送方数据作为数组传递
$sender = array(
'name' => $fromEmail,
'email' => $fromName
);
$emailTemplate->sendTransactional($emailTemplateId, $sender, $emailAddress, $fullName, $data, $store);
然后检查是否有效。