00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class Mage_Core_Model_Email extends Varien_Object
00040 {
00041 protected $_tplVars = array();
00042 protected $_block;
00043
00044 public function __construct()
00045 {
00046
00047 $this->setFromName('Magento');
00048 $this->setFromEmail('magento@varien.com');
00049 $this->setType('text');
00050 }
00051
00052 public function setTemplateVar($var, $value = null)
00053 {
00054 if (is_array($var)) {
00055 foreach ($var as $index=>$value) {
00056 $this->_tplVars[$index] = $value;
00057 }
00058 }
00059 else {
00060 $this->_tplVars[$var] = $value;
00061 }
00062 return $this;
00063 }
00064
00065 public function getTemplateVars()
00066 {
00067 return $this->_tplVars;
00068 }
00069
00070 public function getBody()
00071 {
00072 $body = $this->getData('body');
00073 if (empty($body) && $this->getTemplate()) {
00074 $this->_block = Mage::getModel('core/layout')->createBlock('core/template', 'email')
00075 ->setArea('frontend')
00076 ->setTemplate($this->getTemplate());
00077 foreach ($this->getTemplateVars() as $var=>$value) {
00078 $this->_block->assign($var, $value);
00079 }
00080 $this->_block->assign('_type', strtolower($this->getType()))
00081 ->assign('_section', 'body');
00082 $body = $this->_block->toHtml();
00083 }
00084 return $body;
00085 }
00086
00087 public function getSubject()
00088 {
00089 $subject = $this->getData('subject');
00090 if (empty($subject) && $this->_block) {
00091 $this->_block->assign('_section', 'subject');
00092 $subject = $this->_block->toHtml();
00093 }
00094 return $subject;
00095 }
00096
00097 public function send()
00098 {
00099 if (Mage::getStoreConfigFlag('system/smtp/disable')) {
00100 return $this;
00101 }
00102
00103 $mail = new Zend_Mail();
00104
00105 if (strtolower($this->getType()) == 'html') {
00106 $mail->setBodyHtml($this->getBody());
00107 }
00108 else {
00109 $mail->setBodyText($this->getBody());
00110 }
00111
00112 $mail->setFrom($this->getFromEmail(), $this->getFromName())
00113 ->addTo($this->getToEmail(), $this->getToName())
00114 ->setSubject($this->getSubject());
00115 $mail->send();
00116
00117 return $this;
00118 }
00119 }