Mail.php
00001 <?php
00014 class Dsao_Mail extends Zend_Mail
00015 {
00025 public function __construct(Dsao_User $user = null, $subject = null, $content = null)
00026 {
00027 parent::__construct('utf-8');
00028
00029
00030 if (null === parent::$_defaultTransport)
00031 {
00032
00033 if (Dsao_Registry::get('config')->mail->transport == 'smtp')
00034 {
00035 $transport = new Zend_Mail_Transport_Smtp
00036 (Dsao_Registry::get('config')->mail->smtp->server,
00037 iterator_to_array(Dsao_Registry::get('config')->mail->smtp->config));
00038 }
00039 else
00040 {
00041 $transport = new Zend_Mail_Transport_Sendmail();
00042 }
00043
00044 parent::setDefaultTransport($transport);
00045 }
00046
00047
00048 $this->setFrom(Dsao_Registry::get('config')->mail->sender, 'DSAo-Md Mailer');
00049
00050
00051 if (null !== $user)
00052 {
00053 $this->addTo($user->emailAddress, $user->username);
00054 }
00055
00056
00057
00058
00059 if (null !== $content)
00060 {
00061 $username = (null === $user ? null : $user->username);
00062
00063 $this->setBodyText($content, $username);
00064 }
00065
00066
00067 if (null !== $subject)
00068 {
00069 $this->setSubject($subject);
00070 }
00071 }
00072
00079 public function send($transport = null)
00080 {
00081 try
00082 {
00083
00084 @parent::send($transport);
00085
00086 return true;
00087 }
00088
00089 catch (Zend_Mail_Transport_Exception $e)
00090 {
00091 Dsao_View_Smarty::debug('mailException', $e->getMessage());
00092
00093 Dsao_Registry::get('log')->err('global_email_error_sent');
00094
00095 return false;
00096 }
00097 }
00098
00109 public function setBodyText($txt, $username = null, $charset = null, $encoding = Zend_Mime::ENCODING_QUOTEDPRINTABLE)
00110 {
00111
00112 $header = Dsao_View_Smarty::sprintf
00113 ('global_email_header', array('username' => $username));
00114
00115 $footer = Dsao_Registry::get('translate')->_('global_email_footer');
00116
00117 return parent::setBodyText($header.$txt."\n".$footer, $charset, $encoding);
00118 }
00119
00127 public function setSubject($subject)
00128 {
00129 return parent::setSubject('DSAo-Md: '.$subject);
00130 }
00131 }