本文介绍了在Magento中以编程方式发送电子邮件失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么配置/系统/邮件发送设置中无法为您的smtp服务器指定用户名和密码?

Why is there nowhere in the Configuration/System/Mail Sending Settings to specify a user name and password for your smtp server?

为了解决这个问题,请问需要对本文中概述的getMail()进行更改:

To get around this, do you need to make the changes to getMail() outlined in this post:http://www.magentocommerce.com/boards/viewthread/1073/P30/

我想做一些非常简单的事情:

- 创建电子邮件模板

- 不必在任何配置文件中引用该模板。

- 以编程方式使用上面定义的模板发送电子邮件

- 替代模板中任何标签的供应值

- 提供收件人电子邮件地址

- 提供其他位,如从地址

I want to do something very simple:
- create an e-mail template
- do not have to make reference to that template in any config files.
- programmatically send an e-mail using the template defined above
- supply values to replace any tags in the template
- supply recipient e-mail addresses
- supply other bits, like a from address

所以第一步 - 创建一个模板。

- 在配置/事务电子邮件中我相信我应该看到一个模板列表。我什么也没看见。但是如果我添加一个新的模板,我可以从模板列表中选择。

- 给模板一个名字Bob。

- 添加一些vars到模板中:

myvar1 = {{var myvar1}}

myvar2 = {{var myvar2}}

- 保存模板;它的ID为1.

So first step - create a template.
- In Confguration/Transactional Emails I believe I am supposed to see a list of templates. I see nothing. But if I add a new template, I can select from a list of templates.
- Give template a name of "Bob".
- Add a few vars to the template:
myvar1={{var myvar1}}
myvar2={{var myvar2}}
- Save the template; it is given an Id of 1.

现在通过控制器操作以编程方式发送电子邮件:

- 无需更改LINEEND在Mime.php中,因为它已经在版本1.4.2.0中设置为\\\
b
- 在Template.php中更改getMail(),如本文中所指定的:

- 在控制器操作中写入代码以发送电子邮件:

Now send the e-mail programmatically from a controller action:
- No need to make change to LINEEND in Mime.php as it is already set to \n in version 1.4.2.0
- Make changes to getMail() in Template.php as specified in this post: http://www.magentocommerce.com/boards/viewthread/1073/P30/
- Write code in the controller action to send the e-mail:

    This returns nothing:
    $emailTemplate  = Mage::getModel('core/email_template')->loadDefault('no matter what goes here emailTemplate is not set');

    This does return an email template:
    $emailTemplate  = Mage::getModel('core/email_template')->loadByCode('Bob');

    but the call to send below fails:
    $emailTemplate->setSenderEmail('[email protected]');
    $emailTemplate->setSenderName('Steve');
    $emailTemplateVariables = array();
    $emailTemplateVariables['myvar1'] = 'TestValue1';
    $emailTemplateVariables['myvar2'] = 'TestValue2';
    // $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables); -- this returns nothing
    $emailTemplate->send('[email protected]','John', $emailTemplateVariables);
In the system.log I get the warning below, and no e-mail ever arrives.
Warning: stream_socket_enable_crypto() [<a href='streams.crypto'>streams.crypto</a>]: this stream does not support SSL/crypto  in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\magento\lib\Zend\Mail\Protocol\Smtp.php on line 206

我应该使用loadByCode吗?我希望有一些值得的文档(对于loadByCode的帮助是通过代码加载模板!!)。我应该使用send,sendTransactional吗?哦,对于一些质量文件。

Should I be using loadByCode? I wish there was some worthwhile documentation (the help for loadByCode is "Load template by code" !!). Should I be using send, sendTransactional? Oh for a bit of quality documentation.

谢谢

推荐答案

在这里看到2个问题。

1。如何配置Magento邮件系统以使用smtp协议?

您有麻烦,因为Magento是使用默认主机邮寄。所以它将在安装它的机器上搜索它。

You are having trouble for this because Magento is made to use default host mailing. So it will search for it on the machine where it is installed.

如果要配置smtp服务器,我建议使用这个扩展名:

If you want to configure a smtp server, I would recommend using this extension : http://www.magentocommerce.com/magento-connect/ziq2004/extension/460/advanced-smtp--artson.it

我发现使用和配置很简单。

I found it simple to use and configure.

2。如何在您的自定义模块中发送邮件

您可以先在配置/事务性电子邮件中创建模板,标记身份识别符,这将是您的标识符

You can first create your template in Confguration/Transactional Emails, mark down the Id for it will be your identifier

然后,只需使用此代码在您的模块中发送邮件

Then, simply use this code to send the mail in your module

<?php
// The Id you just marked...
$templateId = 1;

// Define the sender, here we query Magento default email (in the configuration)
// For customer support email, use : 'trans_email/ident_support/...'
$sender = Array('name' => Mage::getStoreConfig('trans_email/ident_general/name'),
                'email' => Mage::getStoreConfig('trans_email/ident_general/email'));

// Set you store
// This information may be taken from the current logged in user
$store = Mage::app()->getStore();

// In this array, you set the variables you use in your template
$vars = Array('my_var' => $my_var,
              'another_var' => 12);

// You don't care about this...
$translate  = Mage::getSingleton('core/translate');

// Send your email
Mage::getModel('core/email_template')->sendTransactional($templateId,
                                                         $sender,
                                                         '[email protected]',
                                                         'Recipient Name',
                                                         $vars,
                                                         $store->getId());

// You don't care as well
$translate->setTranslateInline(true);
?>

希望这将有助于您

这篇关于在Magento中以编程方式发送电子邮件失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:45