Exemple #1
0
 public static function send($option = null)
 {
     try {
         $email = Email::forge();
         $email->from(Config::get('email.defaults.from.email'), Config::get('email.defaults.from.name'));
         $to = $option->to;
         if (is_string($to)) {
             $email->to($to);
         } elseif (is_array($to)) {
             $email->to(Config::get('email.defaults.from.email'), Config::get('email.defaults.from.name'));
             $email->bcc($to);
         }
         $email->subject(html_entity_decode($option->subject, ENT_QUOTES));
         if (!empty($option->attach)) {
             $email->attach(DOCROOT . $option->attach);
         }
         $email->html_body(View::forge('email/' . $option->view, $option->content));
         $email->send();
     } catch (\EmailSendingFailedException $e) {
         Log::write('ERROR', $e->getMessage(), 'Send_email');
         return false;
     } catch (\EmailValidationFailedException $e) {
         Log::write('ERROR', $e->getMessage(), 'Validation_email');
         return false;
     } catch (Exception $e) {
         Log::write('ERROR', $e->getMessage(), 'Exception');
         return false;
     }
     return true;
 }
Exemple #2
0
 public static function sendEmail(EmailOptions $emailOptions)
 {
     // Load FuelPHP Email Package
     \Package::load("email");
     // Create an Email instance
     $email = \Email\Email::forge();
     // Set the "email to"
     foreach ($emailOptions->to as $to) {
         $email->to($to);
     }
     // Set the subject
     $email->subject($emailOptions->subject);
     // And set the body.
     $view = \View::forge('emails/' . $emailOptions->emailTypeName, $emailOptions->vars);
     $email->html_body($view);
     // Try sending the email
     try {
         $response = $email->send();
     } catch (\EmailValidationFailedException $e) {
         $response = false;
     } catch (\EmailSendingFailedException $e) {
         $response = false;
     } catch (\Exception $e) {
         $response = false;
     }
     return $response;
 }
 public function action_forgot()
 {
     \Auth\Auth::check() and \Fuel\Core\Response::redirect("user");
     $val = \Fuel\Core\Validation::forge('forgot');
     if (\Fuel\Core\Input::method() == "POST") {
         if ($val->run()) {
             try {
                 $username = \Fuel\Core\Input::post('email');
                 $user = Model_User::find('first', array('where' => array(array('username', 'LIKE', "{$username}"), 'or' => array(array('email', 'LIKE', "{$username}")))));
                 if (!$user) {
                     throw new \Auth\SimpleUserUpdateException("Invalid username or email");
                 }
                 $old_password = \Auth\Auth::reset_password($user->username);
                 $new_password = \Fuel\Core\Str::random();
                 \Auth\Auth::update_user(array('password' => $new_password, 'old_password' => $old_password), $user->username);
                 // Create an instance
                 $email = \Email\Email::forge();
                 // Set the from address
                 $email->from('*****@*****.**', 'ITNT Time Sheets');
                 // Set the to address
                 $email->to($user->email, $user->first_name . " " . $user->last_name);
                 // Set a subject
                 $email->subject('ITNT Time Sheets Password Reset');
                 // Set multiple to addresses
                 //                            $email->bcc(array(
                 //                                '*****@*****.**' => 'Gavin Murambadoro',
                 //                            ));
                 // Set a html body message
                 $email->html_body(\View::forge('includes/email/forgot', array('user' => $user, 'password' => $new_password)));
                 if ($email->send()) {
                     $this->template->set_global('login_success', "Your password has been reset and an email was sent to {$user->email}");
                 } else {
                     $this->template->set_global('login_error', "Your password was reset but we could not send you an email. Your new password is {$new_password}. Make sure that you copy this before leaving this page.");
                 }
             } catch (\SimpleUserUpdateException $exception) {
                 $this->template->set_global('login_error', "User Error: {$exception->getMessage()}");
             } catch (\EmailValidationFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Validation Error: {$exception->getMessage()}");
             } catch (\EmailSendingFailedException $exception) {
                 $this->template->set_global('login_error', "Mail Error: {$exception->getMessage()}");
             } catch (Exception $exception) {
                 $this->template->set_global('login_error', "General Error: {$exception->getMessage()}");
             }
         } else {
             $this->template->set_global('login_error', $val->error());
         }
     }
     $this->template->set_global('val', $val, false);
     $this->template->title = 'Forgot Password';
     $this->template->content = View::forge('user/forgot');
 }
Exemple #4
0
 public function sendmail($data)
 {
     Package::load('email');
     $email = Email::forge();
     $email->from($data['from'], $data['from_name']);
     $email->to($data['to'], $data['to_name']);
     $email->subject($data['subject']);
     $email->body($data['body']);
     $email->send();
 }