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/
{
/** @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/
相关文章推荐
- Notifier chain 全面分析
- uva 10780 - Again Prime? No Time.(数论)
- hit_training_20140403
- AIX系统Oracle 10g RAC 维护之--OCR和 VOTE disk 管理
- [leetcode]Climbing Stairs
- 虚拟机下11g r2 RAC安装root时报:Timed out waiting for the CRS stack to start. .
- http://www.zhaiquanjiaoyi.com/i/iu
- Table 'table_name' is marked as crashed and last (automatic?) repair failed解决办法
- PAT 1014. Waiting in Line
- 4月第一周.COM域名增近9万居首 域名.AISA减2.5万
- [Leetcode] Container With Most Water
- ZK Intbox的Constraint
- 关于防止DCIM里面的.thumbnails生成
- httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0
- hive.metastore.HiveMetaStoreClient
- 2048-AI程序算法分析
- wait() sleep() synchronized()
- int main(int argc, char** argv)
- HDU 4012 Paint on a Wall
- 每个Zone访问的建立(Lead)、激活(Active)和跟踪(Trail)的时序