예제 #1
0
 public static function SendMailFunction($mail_to, $mail_from, $message = "", $subject = "", $cc = [])
 {
     Yii::import('application.extensions.phpmailer.JPhpMailer');
     $mail = new JPhpMailer();
     $__smtp = $mail->__smtp;
     if (is_null($mail_to)) {
         $mail_to = $__smtp['addreply'];
     }
     if (is_null($mail_from)) {
         $mail_from = $__smtp['addreply'];
     }
     $mail_arr = explode(",", $mail_to);
     if ($subject == "") {
         $subject = Yii::t('trans', 'Site title');
     }
     $mail->IsSMTP();
     $mail->SMTPSecure = 'ssl';
     $mail->Host = $__smtp['host'];
     $mail->SMTPAuth = $__smtp['auth'];
     $mail->Port = $__smtp['port'];
     $mail->Username = $__smtp['username'];
     $mail->Password = $__smtp['password'];
     $mail->AddReplyTo($mail_from, $mail_from);
     $mail->SetFrom($mail_from, $mail_from);
     if (!empty($cc)) {
         if (is_array($cc) && count($cc) == 2) {
             $mail->AddCC($cc[0], $cc[1]);
         } else {
             if (is_array($cc)) {
                 $mail->AddCC($cc[0]);
             } else {
                 $mail->AddCC($cc);
             }
         }
     }
     $mail->Subject = $subject;
     $mail->MsgHTML($message);
     $mail->CharSet = "utf-8";
     foreach ($mail_arr as $email) {
         $mail->AddAddress(trim($email));
     }
     if ($mail->Send()) {
     }
 }
 private function send_notification_email($controller, $user, $uuid)
 {
     $mailer = new JPhpMailer(true);
     // $mailer->SingleTo = true;
     try {
         $mailer->Subject = 'Rags Blind Draw Password Reset';
         $mailer->SetFrom('*****@*****.**');
         $mailer->AddReplyTo('*****@*****.**');
         $mailer->MsgHTML($controller->renderPartial('password_reset_email', array('uuid' => $uuid), true));
         $mailer->AddAddress($this->email, $user->f_name . ' ' . $user->l_name);
         $mailer->send();
     } catch (phpmailerException $e) {
         $error = $e->errorMessage();
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
     if ($error) {
         Yii::app()->user->setFlash('error', $error);
         return false;
     }
     Yii::app()->user->setFlash('success', 'Please check your email and follow the link to reset your password');
     return true;
 }
예제 #3
0
파일: Utility.php 프로젝트: alfinresa/demo
 public static function sentEmail($setFromEmail, $setFromName, $emailDestination, $nameDestination, $subject, $msg, $category = 0, $cc = null, $attachment = null)
 {
     /*
     	list category
     	0=common, 1=registration, 2=vacancy, 3=test_call, 4=message, 5=finance
     */
     Yii::import('ext.jphpmailer.JPhpMailer');
     Yii::import('application.modules.email.models.CcnSendEmailLog');
     $mail = new JPhpMailer();
     //log email into database
     $emailLog = new CcnSendEmailLog();
     $emailLog->category = $category;
     $emailLog->date_inserted = date('Y-m-d H:i:s');
     $emailLog->date_sent = date('Y-m-d H:i:s');
     $emailLog->header_from = $setFromEmail;
     $emailLog->email_to = $emailDestination;
     $emailLog->subject = $subject;
     $emailLog->msg = $msg;
     if ($_SERVER["HTTP_HOST"] == 'localhost' || $_SERVER['SERVER_ADDR'] == '192.168.1.250') {
         //in localhost or testing condition
         //smtp google
         $mail->IsSMTP();
         $mail->SMTPSecure = "ssl";
         $mail->SMTPAuth = true;
         // enable SMTP authentication
         $mail->Host = "smtp.gmail.com";
         // sets the SMTP server
         $mail->Port = 465;
         // set the SMTP port for the GMAIL server
         $mail->Username = "******";
         // SMTP account username
         $mail->Password = "******";
         $mail->SetFrom($setFromEmail, $setFromName);
         $mail->Subject = $subject;
         $mail->MsgHTML($msg);
         //$options  = WebOption::model()->findByPk(1);
         //$emailDestination = $options->email_testing;
         $mail->AddAddress($emailDestination, $nameDestination);
         if ($cc != null && count($cc) > 0) {
             foreach ($cc as $to => $name) {
                 $mail->AddAddress($to, $name);
             }
         }
         if ($attachment != null) {
             $mail->addAttachment($attachment);
         }
     } else {
         //live server
         $mail->IsMail();
         $mail->SetFrom($setFromEmail, $setFromName);
         $mail->Subject = $subject;
         $mail->MsgHTML($msg);
         $mail->AddAddress($emailDestination, $nameDestination);
         $mail->AddReplyTo($setFromEmail, $setFromName);
         if ($attachment != null) {
             $mail->addAttachment($attachment);
         }
         if ($cc != null && count($cc) > 0) {
             foreach ($cc as $to => $name) {
                 $mail->AddAddress($to, $name);
             }
         }
     }
     //	file_put_contents('assets/cek_email.html', $msg);
     if ($_SERVER["HTTP_HOST"] == 'localhost') {
         $emailLog->is_sended = 1;
         $emailLog->save();
         $file = fopen('assets/localhost_email_' . $emailDestination . '.html', 'w+');
         fwrite($file, $msg);
         fclose($file);
         return true;
     } else {
         if ($mail->Send()) {
             $emailLog->is_sended = 1;
             $emailLog->save();
             return true;
         } else {
             $emailLog->is_sended = 0;
             $emailLog->save();
             return false;
         }
     }
 }
 /**
  * Sent Email
  */
 public static function sendEmail($to_email, $to_name, $subject, $message, $type, $cc = null, $attachment = null)
 {
     ini_set('max_execution_time', 0);
     ob_start();
     Yii::import('application.extensions.phpmailer.JPhpMailer');
     $model = self::model()->findByPk(1, array('select' => 'mail_contact, mail_name, mail_from, mail_smtp, smtp_address, smtp_port, smtp_username, smtp_password, smtp_ssl'));
     $mail = new JPhpMailer();
     if ($model->mail_smtp == 1 || $_SERVER["SERVER_ADDR"] == '127.0.0.1' || $_SERVER["HTTP_HOST"] == 'localhost') {
         //in localhost or testing condition
         //smtp google
         $mail->IsSMTP();
         // Set mailer to use SMTP
         $mail->Host = $model->smtp_address;
         // Specify main and backup server
         $mail->Port = $model->smtp_port;
         // set the SMTP port
         $mail->SMTPAuth = true;
         // Enable SMTP authentication
         $mail->Username = $model->smtp_username;
         // SES SMTP  username
         $mail->Password = $model->smtp_password;
         // SES SMTP password
         if ($model->smtp_ssl != 0) {
             $mail->SMTPSecure = $model->smtp_ssl == 1 ? "tls" : "ssl";
         }
         // Enable encryption, 'ssl' also accepted
     } else {
         //live server
         $mail->IsMail();
     }
     /**
      * 0 = to admin
      * 1 = to user
      */
     if ($type == 0) {
         $mail->SetFrom($to_email, $to_name);
         $mail->AddReplyTo($to_email, $to_name);
         $mail->AddAddress($model->mail_contact, $model->mail_name);
     } else {
         $mail->SetFrom($model->mail_from, $model->mail_name);
         $mail->AddReplyTo($model->mail_from, $model->mail_name);
         $mail->AddAddress($to_email, $to_name);
     }
     // cc
     if ($cc != null && count($cc) > 0) {
         foreach ($cc as $email => $name) {
             $mail->AddAddress($email, $name);
         }
     }
     // attachment
     if ($attachment != null) {
         $mail->addAttachment($attachment);
     }
     $mail->Subject = $subject;
     $mail->MsgHTML($message);
     if ($mail->Send()) {
         return true;
         //echo 'send';
     } else {
         return false;
         //echo 'no send';
     }
     ob_end_flush();
 }