Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Send extends CI_Controller {
- public function __construct()
- {
- parent::__construct();
- // set library
- $this->load->library('email');
- $config['protocol']='smtp';
- $config['smtp_host'] = 'smtp.gmail.com';
- $config['smtp_port'] = 587;
- $config['smtp_timeout']='30';
- $config['smtp_user'] = 'username@gmail.com';
- $config['smtp_pass'] = '******';
- $config['charset']='utf-8';
- $config['newline']="\r\n";
- $config['wordwrap'] = TRUE;
- $config['mailtype'] = 'html';
- $config['smtp_crypto'] = 'tls';
- $this->email->initialize($config);
- }
- public function end_of_month()
- {
- // get date end this month
- $end = date('Y-m-t');
- // today
- $today = date('Y-m-d');
- if ($today === $end) {
- // send email
- $email = 'customer@gmail.com';
- $this->email->from('no-reply@domain.com', 'Bot');
- $this->email->to($email);
- $this->email->subject('Information for Month');
- $this->email->message('Email every month');
- // get attachment
- $this->email->attach(base_url('/uploads/sample.pdf'));
- // print result
- if ($this->email->send(FALSE))
- {
- // success
- $this->email->print_debugger(array('headers'));
- }
- else
- {
- // error message
- echo $this->email->print_debugger(array('headers'));
- }
- }
- }
- public function every_two_day()
- {
- // set date
- $full_date = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
- $today = date('Y-m-d');
- // loop date
- for ($i=1; $i<=$full_date; $i++) {
- $go_send = $i % 2 ? 1 : 0; //get 2 day from this month
- // if current two day, then send email
- if ($go_send === 0) {
- // get date to match today
- $date = date('Y-m-' . $i);
- if ($today === $date) {
- // send email
- $email = 'customer@gmail.com';
- $this->email->from('no-reply@domain.com', 'Bot');
- $this->email->to($email);
- $this->email->subject('Information for Every 2 day');
- $this->email->message('Email every 2 days');
- // get attachment
- $this->email->attach(base_url('/uploads/sample.pdf'));
- // print result
- if ($this->email->send(FALSE))
- {
- // success
- $this->email->print_debugger(array('headers'));
- }
- else
- {
- // error message
- echo $this->email->print_debugger(array('headers'));
- }
- }
- }
- }
- }
- public function finish()
- {
- // send email
- $email = 'customer@gmail.com';
- $this->email->from('no-reply@domain.com', 'Bot');
- $this->email->to($email);
- $this->email->subject('Information for Finish Transaction');
- $this->email->message('Email completed transaction');
- // get attachment
- $this->email->attach(base_url('/uploads/sample.pdf'));
- // print result
- if ($this->email->send(FALSE))
- {
- // success
- $this->email->print_debugger(array('headers'));
- }
- else
- {
- // error message
- echo $this->email->print_debugger(array('headers'));
- }
- }
- }
- /* End of file Send.php */
- /* Location: ./application/controllers/Send.php */
Add Comment
Please, Sign In to add comment