2

嗨,我以编程方式在 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')

这是错误代码。请帮我

4

3 回答 3

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设置为“否”。

于 2013-10-08T07:09:14.103 回答
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);

然后检查它是否有效。

于 2019-04-09T09:30:48.043 回答
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.logfor 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);

我希望这会对某人有所帮助。

于 2017-08-31T20:35:00.423 回答