Ejemplo n.º 1
0
 /**
  * Sends a message
  *
  * @param mixed $to
  * @param mixed $subject
  * @param string $body
  *
  * @return int
  */
 public function send($to, $subject, $body)
 {
     $result = 0;
     if ($callbackOptions = CallbackConfig::model()->find() and $callbackOptions->enabled) {
         $options = array();
         $emailFrom = null;
         if ($callbackOptions->type == 'smtp') {
             $options['host'] = $callbackOptions->host;
             $options['username'] = $callbackOptions->username;
             $options['password'] = $callbackOptions->password;
             if ($callbackOptions->port) {
                 $options['port'] = $callbackOptions->port;
             }
             if ($callbackOptions->encryption) {
                 $options['encryption'] = $callbackOptions->encryption;
             }
             $emailFrom = $callbackOptions->username;
         } else {
             $admin = CallbackConfig::model()->findByPk(1);
             $emailFrom = $admin->email;
         }
         parent::setTransportOptions($callbackOptions->type, $options);
         $from = array($emailFrom => $callbackOptions->sender);
         $result = parent::send($from, $to, $subject, $body);
     }
     return $result;
 }
 public function SendMail($mail = array())
 {
     $mailer = new YiiMail();
     $mailer->transportType = 'smtp';
     $mailer->transportOptions = array('host' => Config::model()->getValueByKey('host_sendmail'), 'username' => Config::model()->getValueByKey('username_sendmail'), 'password' => Config::model()->getValueByKey('password_sendmail'), 'port' => Config::model()->getValueByKey('port_sendmail'), 'encryption' => Config::model()->getValueByKey('encryption_sendmail'));
     $message = new YiiMailMessage();
     $message->setFrom(array(Config::model()->getValueByKey('username_sendmail') => Config::model()->getValueByKey('displayname_sendmail')));
     $message->setTo(array($mail['mailto']));
     $message->setReplyTo(array($mail['replyto']));
     $message->setSubject($mail['subject']);
     $message->setBody($mail['body'], 'text/html');
     $mailer->send($message);
 }