Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. use PHPMailer\PHPMailer\PHPMailer;
  4. use PHPMailer\PHPMailer\Exception;
  5. class Email extends CI_Controller {
  6.  
  7.  
  8. function __construct(){
  9. parent::__construct();
  10. $this->load->config('email');
  11. $this->load->library('Mymailer');
  12. // load library
  13. }
  14.  
  15. public function index()
  16. {
  17.  
  18. //Create a new PHPMailer instance
  19. $this->Mymailer = new PHPMailer;
  20. //Tell PHPMailer to use SMTP
  21. $this->Mymailer->isSMTP();
  22. //Enable SMTP debugging
  23. // 0 = off (for production use)
  24. // 1 = client messages
  25. // 2 = client and server messages
  26. $this->Mymailer->SMTPDebug = $this->config->item('SMTPDebug');
  27. //Set the hostname of the mail server
  28. $this->Mymailer->Host = "ssl://smtp.gmail.com:465";
  29. $this->Mymailer->SMTPOptions = array(
  30. 'ssl' => array(
  31. 'verify_peer' => false,
  32. 'verify_peer_name' => false,
  33. 'allow_self_signed' => true
  34. )
  35. );
  36. //Set the SMTP port number - likely to be 25, 465 or 587
  37. //$this->Mymailer->Port = $this->config->item('Port');
  38. //Whether to use SMTP authentication
  39. $this->Mymailer->SMTPAuth = $this->config->item('SMTPAuth');
  40. //Username to use for SMTP authentication
  41. $this->Mymailer->Username = $this->config->item('Username');
  42. //Password to use for SMTP authentication
  43. $this->Mymailer->Password = $this->config->item('Password');
  44. //Set who the message is to be sent from
  45. $this->Mymailer->setFrom($this->config->item('Username'), $this->config->item('Name'));
  46. //Set an alternative reply-to address
  47. $this->Mymailer->addReplyTo($this->config->item('Username'), $this->config->item('Name'));
  48. //Set who the message is to be sent to
  49. $this->Mymailer->addAddress('mfathony115@gmail.com', 'John Doe');
  50. //Set the subject line
  51. $this->Mymailer->Subject = 'jajal email';
  52. //Read an HTML message body from an external file, convert referenced images to embedded,
  53. //convert HTML into a basic plain-text alternative body
  54. //$this->Mymailer->msgHTML("dari localhost <h1 class='ok'> dari </h1>");
  55. //$this->Mymailer->set_mailtype("html");
  56. $msg = "oookk";
  57. //$this->Mymailer->set_header('MIME-Version','1.0; charset=utf-8');
  58. //$this->Mymailer->set_header('Content-type','text/html');
  59. $this->Mymailer->isHTML(true);
  60. $this->Mymailer->Body = $msg;
  61. //Replace the plain text body with one created manually
  62. $this->Mymailer->AltBody = 'This is a plain-text message body';
  63. //Attach an image file
  64. //$this->Mymailer->addAttachment('images/phpmailer_mini.png');
  65. //send the message, check for errors
  66. if (!$this->Mymailer->send()) {
  67. echo 'Mailer Error: ' . $this->Mymailer->ErrorInfo;
  68. } else {
  69. echo 'Message sent!';
  70. }
  71. }
  72.  
  73. function template_email(){
  74. $this->load->view('Email');
  75. }
  76.  
  77. }
  78.  
  79. /* End of file mail.php */
  80. /* Location: ./application/controllers/conten_admin/mail.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement