Exemplo n.º 1
0
 function email_sender($report_name, $start_date, $end_date, $district_or_region, $vals, $store)
 {
     //setting the connection variables
     $config['protocol'] = 'smtp';
     $config['smtp_host'] = 'ssl://smtp.googlemail.com';
     $config['smtp_port'] = 465;
     $config['smtp_user'] = stripslashes('*****@*****.**');
     $config['smtp_pass'] = stripslashes('projectDVI');
     ini_set("SMTP", "ssl://smtp.gmail.com");
     ini_set("smtp_port", "465");
     ini_set("max_execution_time", "50000");
     if ($vals == 1) {
         $emails = Emails::getProvinceEmails($district_or_region);
     } else {
         if ($vals == 2) {
             $emails = Emails::getDistrictEmails($district_or_region);
         } else {
             if ($vals == 3) {
                 $emails = Emails::getEmails();
             }
         }
     }
     //pulling emails from the DB
     $this->load->library('email', $config);
     $path = $_SERVER["DOCUMENT_ROOT"];
     $file = $path . "/DVI/application/pdf/" . $report_name;
     //puts the path where the pdf's are stored
     foreach ($emails as $email) {
         $this->email->attach($file);
         $address = $email['email'];
         $this->email->set_newline("\r\n");
         $start_text_date = date("M j, Y", strtotime($start_date));
         $end_text_date = date("M j, Y", strtotime($end_date));
         $this->email->from('*****@*****.**', "DVI MAILER");
         //user variable displays current user logged in from sessions
         $this->email->to("{$address}");
         $this->email->subject("{$store}" . ' MONTHLY REPORT.');
         $this->email->message('Please find the Report Attached for ' . "{$store}" . ' Period of ' . "{$start_text_date}" . ' to ' . "{$end_text_date}");
         //success message else show the error
         if ($this->email->send()) {
             echo 'Your email was sent, successfully to ' . $address . '<br/>';
             //unlink($file);
             $this->email->clear(TRUE);
         } else {
             show_error($this->email->print_debugger());
         }
     }
     ob_end_flush();
     unlink($file);
     //delete the attachment after sending to avoid clog up of pdf's
 }