Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 在Magento中以编程方式发送电子邮件失败_Email_Magento - Fatal编程技术网

Email 在Magento中以编程方式发送电子邮件失败

Email 在Magento中以编程方式发送电子邮件失败,email,magento,Email,Magento,为什么在配置/系统/邮件发送设置中没有指定smtp服务器的用户名和密码 要解决此问题,是否需要对getMail进行本文中概述的更改: 我想做一些非常简单的事情: -创建电子邮件模板 -不必在任何配置文件中引用该模板。 -使用上面定义的模板以编程方式发送电子邮件 -提供值以替换模板中的任何标记 -提供收件人电子邮件地址 -提供其他位,如from地址 所以第一步-创建一个模板。 -在配置/交易电子邮件中,我认为我应该看到一个模板列表。我什么也没看见。但是如果我添加一个新模板,我可以从模板列表中进行

为什么在配置/系统/邮件发送设置中没有指定smtp服务器的用户名和密码

要解决此问题,是否需要对getMail进行本文中概述的更改:

我想做一些非常简单的事情: -创建电子邮件模板 -不必在任何配置文件中引用该模板。 -使用上面定义的模板以编程方式发送电子邮件 -提供值以替换模板中的任何标记 -提供收件人电子邮件地址 -提供其他位,如from地址

所以第一步-创建一个模板。 -在配置/交易电子邮件中,我认为我应该看到一个模板列表。我什么也没看见。但是如果我添加一个新模板,我可以从模板列表中进行选择。 -给模板一个Bob的名字。 -向模板中添加几个变量: myvar1={{var myvar1}} myvar2={{var myvar2}} -保存模板;它的Id为1

现在,通过控制器操作以编程方式发送电子邮件: -无需更改Mime.php中的LINEEND,因为在版本1.4.2.0中已将其设置为\n -在Template.php中更改getMail,如本文所述: -在控制器操作中写入代码以发送电子邮件:

    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
我应该使用loadByCode吗?我希望有一些有价值的文档,loadByCode的帮助就是按代码加载模板!!。我应该使用send、sendTransactional吗?哦,需要一些高质量的文档


谢谢

我在Template.php的getMail中取出了数组中的'ssl'=>'tls'元素,我的电子邮件通过了。
如果有人能解释smtp服务器的用户名和密码应该如何指定,以及模板加载方法等方面的差异,我将不胜感激

我在Template.php中的getMail中取出数组中的'ssl'=>'tls'元素,我的电子邮件通过了。
如果有人能解释smtp服务器的用户名和密码应该如何指定,以及模板加载方法等方面的差异,我将不胜感激

我在这里看到两个问题

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

您遇到了问题,因为Magento被设置为使用默认主机邮件。因此,它将在安装它的机器上搜索它

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

我发现它易于使用和配置

二,。如何在自定义模块中发送邮件

您可以首先在配置/交易电子邮件中创建模板,标记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);
?>
希望这对你有帮助


关于,

我在这里看到两个问题

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

您遇到了问题,因为Magento被设置为使用默认主机邮件。因此,它将在安装它的机器上搜索它

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

我发现它易于使用和配置

二,。如何在自定义模块中发送邮件

您可以首先在配置/交易电子邮件中创建模板,标记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);
?>
希望这对你有帮助


关于,

如果有人正在寻找如何基于现有Magento电子邮件模板发送Magento电子邮件的完整示例代码,以下代码很好用。它不需要任何XML配置。您可以按名称和ID加载模板。在本例中,我按名称加载模板

// This is the name that you gave to the template in System -> Transactional Emails
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Custom Email Template');

// These variables can be used in the template file by doing {{ var some_custom_variable }}
$emailTemplateVariables = array(
'some_custom_variable' => 'Hello World'
);

$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

$emailTemplate->setSenderName('Joe Bloggs');
$emailTemplate->setSenderEmail('test@test.com');
$emailTemplate->setTemplateSubject("Here is your subject");

$emailTemplate->send('recipient@test.com', 'Joanna Bloggs', $emailTemplateVariables);

如果有人正在寻找如何基于现有的Magento电子邮件模板发送Magento电子邮件的完整示例代码,那么以下代码可以很好地工作。它不需要任何XML配置。您可以按名称和ID加载模板。在本例中,我按名称加载模板

// This is the name that you gave to the template in System -> Transactional Emails
$emailTemplate = Mage::getModel('core/email_template')->loadByCode('My Custom Email Template');

// These variables can be used in the template file by doing {{ var some_custom_variable }}
$emailTemplateVariables = array(
'some_custom_variable' => 'Hello World'
);

$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

$emailTemplate->setSenderName('Joe Bloggs');
$emailTemplate->setSenderEmail('test@test.com');
$emailTemplate->setTemplateSubject("Here is your subject");

$emailTemplate->send('recipient@test.com', 'Joanna Bloggs', $emailTemplateVariables);