为什么配置/系统/邮件发送设置中没有任何地方为smtp服务器指定用户名和密码?
要解决这个问题,您是否需要对此帖中列出的getMail()进行更改:http: //www.magentocommerce.com/boards/viewthread/1073/P30/
我想做一些非常简单的事情:
- 创建一个电子邮件模板
- 不必在任何配置文件中引用该模板.
- 使用上面定义的模板以编程方式发送电子邮件
- 提供值以替换模板中的任何标签
- 提供收件人电子邮件地址
- 提供其他位,例如来自地址
所以第一步 - 创建一个模板.
- 在配置/交易电子邮件中我相信我应该看到模板列表.我什么也没看见.但是如果我添加一个新模板,我可以从模板列表中进行选择.
- 为模板命名为"Bob".
- 向模板添加几个变量:
myvar1 = {{var myvar1}}
myvar2 = {{var myvar2}}
- 保存模板; 它的Id为1.
现在以编程方式从控制器操作发送电子邮件:
- 无需在Mime.php中更改为LINEEND,因为它已在版本1.4.2.0中设置为\n
- 在指定的Template.php中对getMail()进行更改在这篇文章中:http://www.magentocommerce.com/boards/viewthread/1073/P30/
- 在控制器动作中编写代码以发送电子邮件:
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('sent@byme.com');
$emailTemplate->setSenderName('Steve');
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'TestValue1';
$emailTemplateVariables['myvar2'] = 'TestValue2';
// $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables); -- this returns nothing
$emailTemplate->send('thisisme@mydomain.com','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
Run Code Online (Sandbox Code Playgroud)
我应该使用loadByCode吗?我希望有一些有价值的文档(loadByCode的帮助是"按代码加载模板"!!).我应该使用send,sendTransactional吗?哦,有一些高质量的文档.
谢谢
我在这里看到2个问题.
1.如何配置Magento邮件系统使用smtp协议?
你遇到了麻烦,因为Magento使用默认的主机邮件.因此它将在安装它的机器上搜索它.
如果你想配置一个smtp服务器,我建议使用这个扩展名:http://www.magentocommerce.com/magento-connect/ziq2004/extension/460/advanced-smtp--artson.it
我发现使用和配置简单.
2.如何在自定义模块中发送邮件
您可以先在配置/交易电子邮件中创建模板,将Id标记为您的标识符
然后,只需使用此代码即可在模块中发送邮件
<?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,
'recipient@gmail.com',
'Recipient Name',
$vars,
$store->getId());
// You don't care as well
$translate->setTranslateInline(true);
?>
Run Code Online (Sandbox Code Playgroud)
希望对你有帮助
问候,
归档时间: |
|
查看次数: |
10367 次 |
最近记录: |