Guest User

Untitled

a guest
Jan 29th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Send extends CI_Controller {
  5.  
  6. public function __construct()
  7. {
  8. parent::__construct();
  9.  
  10. // set library
  11. $this->load->library('email');
  12.  
  13. $config['protocol']='smtp';
  14. $config['smtp_host'] = 'smtp.gmail.com';
  15. $config['smtp_port'] = 587;
  16. $config['smtp_timeout']='30';
  17. $config['smtp_user'] = 'username@gmail.com';
  18. $config['smtp_pass'] = '******';
  19. $config['charset']='utf-8';
  20. $config['newline']="\r\n";
  21. $config['wordwrap'] = TRUE;
  22. $config['mailtype'] = 'html';
  23. $config['smtp_crypto'] = 'tls';
  24.  
  25. $this->email->initialize($config);
  26. }
  27.  
  28. public function end_of_month()
  29. {
  30. // get date end this month
  31. $end = date('Y-m-t');
  32.  
  33. // today
  34. $today = date('Y-m-d');
  35.  
  36. if ($today === $end) {
  37. // send email
  38. $email = 'customer@gmail.com';
  39.  
  40. $this->email->from('no-reply@domain.com', 'Bot');
  41. $this->email->to($email);
  42.  
  43. $this->email->subject('Information for Month');
  44. $this->email->message('Email every month');
  45.  
  46. // get attachment
  47. $this->email->attach(base_url('/uploads/sample.pdf'));
  48.  
  49. // print result
  50. if ($this->email->send(FALSE))
  51. {
  52. // success
  53. $this->email->print_debugger(array('headers'));
  54. }
  55. else
  56. {
  57. // error message
  58. echo $this->email->print_debugger(array('headers'));
  59. }
  60. }
  61. }
  62.  
  63. public function every_two_day()
  64. {
  65. // set date
  66. $full_date = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
  67. $today = date('Y-m-d');
  68.  
  69. // loop date
  70. for ($i=1; $i<=$full_date; $i++) {
  71. $go_send = $i % 2 ? 1 : 0; //get 2 day from this month
  72.  
  73. // if current two day, then send email
  74. if ($go_send === 0) {
  75.  
  76. // get date to match today
  77. $date = date('Y-m-' . $i);
  78.  
  79. if ($today === $date) {
  80. // send email
  81. $email = 'customer@gmail.com';
  82.  
  83. $this->email->from('no-reply@domain.com', 'Bot');
  84. $this->email->to($email);
  85.  
  86. $this->email->subject('Information for Every 2 day');
  87. $this->email->message('Email every 2 days');
  88.  
  89. // get attachment
  90. $this->email->attach(base_url('/uploads/sample.pdf'));
  91.  
  92. // print result
  93. if ($this->email->send(FALSE))
  94. {
  95. // success
  96. $this->email->print_debugger(array('headers'));
  97. }
  98. else
  99. {
  100. // error message
  101. echo $this->email->print_debugger(array('headers'));
  102. }
  103. }
  104.  
  105. }
  106. }
  107. }
  108.  
  109. public function finish()
  110. {
  111. // send email
  112. $email = 'customer@gmail.com';
  113.  
  114. $this->email->from('no-reply@domain.com', 'Bot');
  115. $this->email->to($email);
  116.  
  117. $this->email->subject('Information for Finish Transaction');
  118. $this->email->message('Email completed transaction');
  119.  
  120. // get attachment
  121. $this->email->attach(base_url('/uploads/sample.pdf'));
  122.  
  123. // print result
  124. if ($this->email->send(FALSE))
  125. {
  126. // success
  127. $this->email->print_debugger(array('headers'));
  128. }
  129. else
  130. {
  131. // error message
  132. echo $this->email->print_debugger(array('headers'));
  133. }
  134. }
  135.  
  136. }
  137.  
  138. /* End of file Send.php */
  139. /* Location: ./application/controllers/Send.php */
Add Comment
Please, Sign In to add comment