您的位置:首页 > 大数据 > 人工智能

magento send email

2014-04-10 18:13 656 查看
protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null)

{

/** @var $mailer Mage_Core_Model_Email_Template_Mailer */

$mailer = Mage::getModel('core/email_template_mailer');

$emailInfo = Mage::getModel('core/email_info');

$emailInfo->addTo($this->getEmail(), $this->getName());

$mailer->addEmailInfo($emailInfo);

// Set all required params and send emails

$mailer->setSender(Mage::getStoreConfig($sender, $storeId));

$mailer->setStoreId($storeId);

$mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));

$mailer->setTemplateParams($templateParams);

$mailer->send();

return $this;

}
app/code/core/mage/core/model/email/template/mailer.php send()->app/code/core/mage/core/model/email/template.php[sendTransactional()]
###################################################
if (is_numeric($templateId)) {
$this->load($templateId);

} else {

$localeCode = Mage::getStoreConfig('general/locale/code', $storeId);

$this->loadDefault($templateId, $localeCode); // when select default template fromlocale

}
###################################################
->app/code/core/mage/core/model/email/template.php[send()]
->lib/zend/mail.php[send()]
->lib/zend/mail/transport/abstract.php[send()]
->lib/zend/mail/transport/sendmail.php[_sendMail()]
###################################################
public function _sendMail()

{

if ($this->parameters === null) {

set_error_handler(array($this, '_handleMailErrors'));

$result = mail(

$this->recipients,

$this->_mail->getSubject(),

$this->body,

$this->header);

restore_error_handler();

} else {

if(!is_string($this->parameters)) {

/**

* @see Zend_Mail_Transport_Exception

*

* Exception is thrown here because

* $parameters is a public property

*/

#require_once 'Zend/Mail/Transport/Exception.php';

throw new Zend_Mail_Transport_Exception(

'Parameters were set but are not a string'

);

}

set_error_handler(array($this, '_handleMailErrors'));

$result = mail(

$this->recipients,

$this->_mail->getSubject(),

$this->body,

$this->header,

$this->parameters);

restore_error_handler();

}

if ($this->_errstr !== null || !$result) {

/**

* @see Zend_Mail_Transport_Exception

*/

#require_once 'Zend/Mail/Transport/Exception.php';

throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);

}

}
###################################################

set default template from locale:

system.xml
add configuration here
config.xml
add configuration here
put the file order.html in app/locale/your language/template/email/notifyemail/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: