Beispiel #1
0
 /**
  * Get mail transport
  * 
  * @return Zend_Mail_Transport
  */
 public static function getMailTransport()
 {
     if (self::$_transport == null) {
         require_once LIB_DIR . DS . 'phpmailer' . DS . 'class.phpmailer.php';
         require_once LIB_DIR . DS . 'phpmailer' . DS . 'class.smtp.php';
         $config = Gio_Core_Module::getConfig('mail', true);
         self::$_transport = new PHPMailer();
         self::$_transport->CharSet = 'utf-8';
         switch ($config['protocol']['protocol']) {
             case 'mail':
                 self::$_transport->Mailer = 'mail';
                 break;
             case 'smtp':
                 self::$_transport->Mailer = 'smtp';
                 $options = array();
                 /**
                  * Check host setting
                  */
                 if (isset($config['smtp']['host'])) {
                     $options['host'] = $config['smtp']['host'];
                 }
                 /**
                  * Check port setting
                  */
                 if (isset($config['smtp']['port'])) {
                     $options['port'] = $config['smtp']['port'];
                 }
                 /**
                  * Check authentication settings
                  */
                 if (isset($config['smtp']['username']) && isset($config['smtp']['password'])) {
                     $options['auth'] = 'login';
                     $options['username'] = $config['smtp']['username'];
                     $options['password'] = $config['smtp']['password'];
                 }
                 /**
                  * Check security setting
                  */
                 if (isset($config['smtp']['security'])) {
                     $options['ssl'] = $config['smtp']['security'];
                 }
                 self::$_transport->Host = $options['host'];
                 // specify main and backup server
                 self::$_transport->Port = $options['port'];
                 // set the port to use
                 self::$_transport->SMTPAuth = true;
                 // turn on SMTP authentication
                 self::$_transport->SMTPSecure = $options['ssl'];
                 self::$_transport->Username = $options['username'];
                 // your SMTP username or your gmail username
                 self::$_transport->Password = $options['password'];
                 // your SMTP password or your gmail password
                 break;
         }
     }
     return self::$_transport;
 }
Beispiel #2
0
 /**
  * Provide the link (via email) for user to reset the password
  * 
  * @param string $username
  * @param string $email
  * @return bool Returns false if user is not found or can not send email, 
  * true otherwise
  */
 public static function registerSuccess($username, $email)
 {
     $criteria = array('username' => $username, 'email' => $email);
     $users = self::find($criteria, null, null);
     if ($users == null || count($users) == 0) {
         return false;
     }
     /**
      * Send the confirmation link to reset password via email 
      */
     $user = $users[0];
     $template = Modules_Mail_Services_Template::getByName(Modules_Mail_Models_Template::TEMPLATE_REGISTER_SUCCESS);
     if ($template == null) {
         return;
         //throw new Exception('MAIL_TEMPLATE_NOT_FOUND');
     }
     $search = array(Modules_Mail_Models_Mail::MAIL_VARIABLE_EMAIL, Modules_Mail_Models_Mail::MAIL_VARIABLE_USERNAME);
     $replace = array($user['email'], $user['username']);
     $subject = str_replace($search, $replace, $template['subject']);
     $content = str_replace($search, $replace, $template['body']);
     /**
      * Get mail transport instance
      */
     $mailer = Modules_Mail_Services_Mailer::getMailTransport();
     $mailer->From = $template['from_mail'];
     $mailer->FromName = $template['from_name'];
     $mailer->AddAddress($user['email'], $user['username']);
     $mailer->AddReplyTo($template['reply_to_mail'], $template['reply_to_name']);
     $mailer->WordWrap = 50;
     // set word wrap
     $mailer->IsHTML(true);
     // send as HTML
     $mailer->Subject = $subject;
     $mailer->Body = $content;
     //HTML Body
     $mailer->AltBody = "";
     //Text Body
     if (!$mailer->Send()) {
         return false;
     } else {
         return true;
     }
 }