爲什麼在配置/系統/郵件發送設置中無法爲您的smtp服務器指定用戶名和密碼?以編程方式在Magento中發送電子郵件失敗
要解決這個問題,你需要進行更改,以在這個崗位概述getMail(): http://www.magentocommerce.com/boards/viewthread/1073/P30/
我想要做的東西很簡單:
- 創建一個電子郵件模板
- 不必在任何配置文件中引用該模板。
- 供應值在模板中替換任何標籤
- - 供給收件人的電子郵件地址
- 編程方式使用上述
定義的模板發送電子郵件供應其它位從地址,像
所以第一步 - 創建一個模板。
- 在配置/交易電子郵件我相信我應該看到一個模板列表。我什麼也沒看見。但是如果我添加一個新模板,我可以從模板列表中進行選擇。
- 給模板名稱「Bob」。
- 添加幾瓦爾到模板:
myvar1 = {{VAR myvar1}}
myvar2 = {{VAR myvar2}}
- 保存模板;它的Id爲1.
現在通過編程方式從控制器操作發送電子郵件:
- 無需更改Mime.php中的LINEEND,因爲它已在版本1.4中設置爲\ n。 2.0
- 因爲在這個崗位規定進行更改,getMail()中的template.php: - 寫在控制器動作代碼發送電子郵件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('[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?哦,一點質量文件。
感謝