function email_quote($quote_id, $quote_template, $from, $to, $subject, $body, $cc = NULL, $bcc = NULL)
{
    $CI =& get_instance();
    $CI->load->helper('mailer/phpmailer');
    $CI->load->helper('template');
    $CI->load->helper('pdf');
    $quote = generate_quote_pdf($quote_id, FALSE, $quote_template);
    $db_quote = $CI->mdl_quotes->where('ip_quotes.quote_id', $quote_id)->get()->row();
    $message = nl2br(parse_template($db_quote, $body));
    return phpmail_send($from, $to, $subject, $message, $quote, $cc, $bcc);
}
/**
 * @param $quote_id
 * @param $status string "accepted" or "rejected"
 * @return bool if the email was sent
 */
function email_quote_status($quote_id, $status)
{
    ini_set('display_errors', 'on');
    error_reporting(E_ALL);
    if (!mailer_configured()) {
        return false;
    }
    $CI =& get_instance();
    $CI->load->helper('mailer/phpmailer');
    $quote = $CI->mdl_quotes->where('ip_quotes.quote_id', $quote_id)->get()->row();
    $base_url = base_url('/quotes/view/' . $quote_id);
    $user_email = $quote->user_email;
    $subject = sprintf(trans('quote_status_email_subject'), $quote->client_name, strtolower(lang($status)), $quote->quote_number);
    $body = sprintf(nl2br(trans('quote_status_email_body')), $quote->client_name, strtolower(lang($status)), $quote->quote_number, '<a href="' . $base_url . '">' . $base_url . '</a>');
    return phpmail_send($user_email, $user_email, $subject, $body);
}
Example #3
0
 public function email_payment_receipt($invoice, $template, $from_email, $from_name, $to, $subject, $email_body, $email_footer, $receipt_as_body, $email_cc = NULL, $email_bcc = NULL)
 {
     $filename = 'receipt_' . $invoice->invoice_number;
     $full_filename = 'uploads/temp/' . $filename . '.pdf';
     $this->load->helper($this->mdl_mcb_data->setting('pdf_plugin'));
     $invoice_payments = $this->mdl_invoices->get_invoice_payments($invoice->invoice_id);
     $data = array('invoice' => $invoice, 'invoice_payments' => $invoice_payments);
     $html = $this->load->view('payments/receipt_templates/' . $template, $data, TRUE);
     pdf_create($html, $filename, FALSE);
     $this->load->helper('mailer/phpmailer');
     $email_body = $receipt_as_body ? nl2br($email_body) . $html : $email_body;
     if (!$email_body) {
         $email_body = ' ';
     }
     $email_body .= nl2br($email_footer);
     phpmail_send(array($from_email, $from_name), $to, $subject, $email_body, $full_filename, $email_cc, $email_bcc);
     $this->mdl_invoices->delete_invoice_file($filename . '.pdf');
 }
Example #4
0
 public function quote($quote_id)
 {
     if ($this->mailer_configured == TRUE) {
         if ($this->input->post('btn_send')) {
             $this->load->helper('phpmailer');
             $quote = modules::run('quotes/generate_pdf', $quote_id, FALSE);
             $from = $this->input->post('from_name') ? array($this->input->post('from_email'), $this->input->post('from_name')) : $this->input->post('from_email');
             $to = $this->input->post('to_email');
             $subject = $this->input->post('subject');
             $message = $this->input->post('body');
             $cc = $this->input->post('to_cc');
             $bcc = $this->input->post('to_bcc');
             if (phpmail_send($from, $to, $subject, $message, $quote, $cc, $bcc)) {
                 redirect('dashboard');
             } else {
                 redirect('mailer/quote/' . $quote_id);
             }
             $this->session->set_flashdata('alert_success', 'Email successfully sent');
             redirect('dashboard');
         }
         $this->load->model('invoices/mdl_templates');
         $this->load->model('quotes/mdl_quotes');
         $this->load->model('email_templates/mdl_email_templates');
         if ($email_template_id = $this->mdl_settings->setting('default_email_template')) {
             $email_template = $this->mdl_email_templates->where('email_template_id', $email_template_id)->get();
             if ($email_template->num_rows()) {
                 $this->layout->set('body', $email_template->row()->email_template_body);
             } else {
                 $this->layout->set('body', '');
             }
         } else {
             $this->layout->set('body', '');
         }
         $this->layout->set('quote', $this->mdl_quotes->where('fi_quotes.quote_id', $quote_id)->get()->row());
         $this->layout->set('quote_templates', $this->mdl_templates->get_quote_templates());
         $this->layout->buffer('content', 'mailer/quote');
         $this->layout->render();
     } else {
         $this->layout->buffer('content', 'mailer/not_configured');
         $this->layout->render();
     }
 }
Example #5
0
 function recover_password($username)
 {
     $this->db->where('username', $username);
     $query = $this->db->get('mcb_users');
     if ($query->num_rows()) {
         $this->load->helper('mailer/phpmailer');
         $user = $query->row();
         if ($user->email_address) {
             $password = random_string();
             $this->db->where('user_id', $user->user_id);
             $this->db->set('password', md5($password));
             $this->db->update('mcb_users');
             $from = $user->email_address;
             $to = $user->email_address;
             $subject = $this->lang->line('password_recovery');
             $email_body = $this->lang->line('password_recovery_email') . ' ';
             $email_body .= $password . '<br />' . anchor(site_url(), $this->lang->line('password_recovery_email_2'));
             $this->mdl_mcb_data->set_session_data();
             phpmail_send($from, $to, $subject, $email_body);
         }
     }
 }
 public function passwordreset($token = null)
 {
     // Check if a token was provided
     if ($token) {
         $this->db->where('user_passwordreset_token', $token);
         $user = $this->db->get('ip_users');
         $user = $user->row();
         if (empty($user)) {
             // Redirect back to the login screen with an alert
             $this->session->set_flashdata('alert_success', trans('wrong_passwordreset_token'));
             redirect('sessions/passwordreset');
         }
         $formdata = array('user_id' => $user->user_id);
         return $this->load->view('session_new_password', $formdata);
     }
     // Check if the form for a new password was used
     if ($this->input->post('btn_new_password')) {
         $new_password = $this->input->post('new_password');
         $user_id = $this->input->post('user_id');
         if (empty($user_id) || empty($new_password)) {
             $this->session->set_flashdata('alert_error', trans('loginalert_no_password'));
             redirect($_SERVER['HTTP_REFERER']);
         }
         // Call the save_change_password() function from users model
         $this->load->model('users/mdl_users');
         $this->mdl_users->save_change_password($user_id, $new_password);
         // Update the user and set him active again
         $db_array = array('user_passwordreset_token' => '');
         $this->db->where('user_id', $user_id);
         $this->db->update('ip_users', $db_array);
         // Redirect back to the login form
         redirect('sessions/login');
     }
     // Check if the password reset form was used
     if ($this->input->post('btn_reset')) {
         $email = $this->input->post('email');
         if (empty($email)) {
             $this->session->set_flashdata('alert_error', trans('loginalert_user_not_found'));
             redirect($_SERVER['HTTP_REFERER']);
         }
         // Test if a user with this email exists
         if ($this->db->where('user_email', $email)) {
             // Create a passwordreset token
             $email = $this->input->post('email');
             $token = md5(time() . $email);
             // Save the token to the database and set the user to inactive
             $db_array = array('user_passwordreset_token' => $token);
             $this->db->where('user_email', $email);
             $this->db->update('ip_users', $db_array);
             // Send the email with reset link
             $this->load->helper('mailer');
             // Preprare some variables for the email
             $email_resetlink = site_url('sessions/passwordreset/' . $token);
             $email_message = $this->load->view('emails/passwordreset', array('resetlink' => $email_resetlink), true);
             $email_from = 'system@' . preg_replace("/^[\\w]{2,6}:\\/\\/([\\w\\d\\.\\-]+).*\$/", "\$1", base_url());
             // Mail the invoice with the pre-configured mailer if possible
             if (mailer_configured()) {
                 $this->load->helper('mailer/phpmailer');
                 if (phpmail_send($email_from, $email, trans('password_reset'), $email_message)) {
                     $email_failed = true;
                     log_message('error', $this->email->print_debugger());
                 }
             } else {
                 $this->load->library('email');
                 // Set email configuration
                 $config['mailtype'] = 'html';
                 $this->email->initialize($config);
                 // Set the email params
                 $this->email->from($email_from);
                 $this->email->to($email);
                 $this->email->subject(trans('password_reset'));
                 $this->email->message($email_message);
                 // Send the reset email
                 if ($this->email->send()) {
                     $email_failed = true;
                     log_message('error', $this->email->print_debugger());
                 }
             }
             // Redirect back to the login screen with an alert
             if (isset($email_failed)) {
                 $this->session->set_flashdata('alert_success', trans('password_reset_failed'));
             } else {
                 $this->session->set_flashdata('alert_success', trans('email_successfully_sent'));
             }
             redirect('sessions/login');
         }
     }
     return $this->load->view('session_passwordreset');
 }