コード例 #1
0
ファイル: email.php プロジェクト: nick-catanchin-ie/common
 /**
  * sends an email using our configs
  * @param  string/array $to       array(array('name'=>'chema','email'=>'chema@'),)
  * @param  [type] $to_name   [description]
  * @param  [type] $subject   [description]
  * @param  [type] $body      [description]
  * @param  [type] $reply     [description]
  * @param  [type] $replyName [description]
  * @param  [type] $file      [description]
  * @return boolean
  */
 public static function send($to, $to_name = '', $subject, $body, $reply, $replyName, $file = NULL)
 {
     require_once Kohana::find_file('vendor', 'php-mailer/phpmailer', 'php');
     $body = Text::nl2br($body);
     //get the unsubscribe link
     $email_encoded = NULL;
     //is sent to a single user get hash to auto unsubscribe
     if (!is_array($to) or count($to) == 1) {
         //from newsletter sent
         if (isset($to[0]['email'])) {
             $email_encoded = $to[0]['email'];
         } else {
             $email_encoded = $to;
         }
         //encodig the email for extra security
         $encrypt = new Encrypt(Core::config('auth.hash_key'), MCRYPT_MODE_NOFB, MCRYPT_RIJNDAEL_128);
         $email_encoded = Base64::fix_to_url($encrypt->encode($email_encoded));
     }
     $unsubscribe_link = Route::url('oc-panel', array('controller' => 'auth', 'action' => 'unsubscribe', 'id' => $email_encoded));
     //get the template from the html email boilerplate
     $body = View::factory('email', array('title' => $subject, 'content' => $body, 'unsubscribe_link' => $unsubscribe_link))->render();
     //sendign via elasticemail
     if (Core::config('email.elastic_active') == TRUE) {
         return self::ElasticEmail($to, $to_name, $subject, $body, core::config('email.notify_email'), "no-reply " . core::config('general.site_name'));
     } else {
         $mail = new PHPMailer();
         $mail->CharSet = Kohana::$charset;
         if (core::config('email.smtp_active') == TRUE) {
             require_once Kohana::find_file('vendor', 'php-mailer/smtp', 'php');
             $mail->IsSMTP();
             //SMTP HOST config
             if (core::config('email.smtp_host') != "") {
                 $mail->Host = core::config('email.smtp_host');
                 // sets custom SMTP server
             }
             //SMTP PORT config
             if (core::config('email.smtp_port') != "") {
                 $mail->Port = core::config('email.smtp_port');
                 // set a custom SMTP port
             }
             //SMTP AUTH config
             if (core::config('email.smtp_auth') == TRUE) {
                 $mail->SMTPAuth = TRUE;
                 // enable SMTP authentication
                 $mail->Username = core::config('email.smtp_user');
                 // SMTP username
                 $mail->Password = core::config('email.smtp_pass');
                 // SMTP password
                 if (core::config('email.smtp_ssl') == TRUE) {
                     $mail->SMTPSecure = "ssl";
                     // sets the prefix to the server
                 }
             }
         }
         $mail->From = core::config('email.notify_email');
         $mail->FromName = "no-reply " . core::config('general.site_name');
         $mail->Subject = $subject;
         $mail->MsgHTML($body);
         if ($file !== NULL) {
             $mail->AddAttachment($file['tmp_name'], $file['name']);
         }
         $mail->AddReplyTo($reply, $replyName);
         //they answer here
         if (is_array($to)) {
             foreach ($to as $contact) {
                 $mail->AddBCC($contact['email'], $contact['name']);
             }
         } else {
             $mail->AddAddress($to, $to_name);
         }
         $mail->IsHTML(TRUE);
         // send as HTML
         if (!$mail->Send()) {
             //to see if we return a message or a value bolean
             Alert::set(Alert::ALERT, "Mailer Error: " . $mail->ErrorInfo);
             return FALSE;
         } else {
             return TRUE;
         }
     }
     return FALSE;
 }
コード例 #2
0
ファイル: oc.php プロジェクト: JeffPedro/project-garage-sale
 /**
  * Encodes the data received, creating a encoded quicklogin string
  * @param string $token user token
  * @param integer $lifetime
  * @param string $url
  */
 public function ql_encode($token = NULL, $url = NULL, $expires = NULL)
 {
     //using default value
     if ($expires === NULL) {
         $expires = time() + $this->_config['ql_lifetime'];
     }
     //URL and token is mandatory
     if ($url === NULL or $token === NULL) {
         return FALSE;
     }
     // Generate a string from the pieces
     $out = implode($this->_config['ql_separator'], array($token, $expires, $url));
     $out = $this->_encrypt->encode($out);
     $out = Base64::fix_to_url($out);
     return $out;
 }