Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * This example shows settings to use when sending via Google's Gmail servers.
  5. * The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
  6. */
  7.  
  8. //SMTP needs accurate times, and the PHP time zone MUST be set
  9. //This should be done in your php.ini, but this is how to do it if you don't have access to that
  10. date_default_timezone_set('Africa/Nairobi');
  11.  
  12. require 'PHPMailer/PHPMailerAutoload.php';
  13. require_once "../config/dbConnect.php";
  14.  
  15. //Create a new PHPMailer instance
  16. $mail = new PHPMailer;
  17.  
  18. //Tell PHPMailer to use SMTP
  19. $mail->isSMTP();
  20.  
  21. //Enable SMTP debugging
  22. // 0 = off (for production use)
  23. // 1 = client messages
  24. // 2 = client and server messages
  25. $mail->SMTPDebug = 0;
  26.  
  27. //Ask for HTML-friendly debug output
  28. $mail->Debugoutput = 'html';
  29.  
  30. //Set the hostname of the mail server
  31. $mail->Host = 'smtp.gmail.com';
  32. // use
  33. // $mail->Host = gethostbyname('smtp.gmail.com');
  34. // if your network does not support SMTP over IPv6
  35.  
  36. //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
  37. $mail->Port = 587;
  38.  
  39. //Set the encryption system to use - ssl (deprecated) or tls
  40. $mail->SMTPSecure = 'tls';
  41.  
  42. //Whether to use SMTP authentication
  43. $mail->SMTPAuth = true;
  44.  
  45.  
  46. $sql = "SELECT users.email,users.FacilityName as u_name FROM drug INNER JOIN users ON users.MinistryRegNum = drug.MinistryRegNum WHERE drug.Expiry_date <= DATE_ADD(CURRENT_DATE,INTERVAL 28 DAY)";
  47. $emails = mysqli_query($link,$sql);
  48.  
  49. while($_user = mysqli_fetch_array($emails)){
  50.  
  51. //Username to use for SMTP authentication - use full email address for gmail
  52. $mail->Username = "bbitalex@gmail.com";
  53.  
  54. //Password to use for SMTP authentication
  55. $mail->Password = "alex2017";
  56.  
  57. //Set who the message is to be sent from
  58. $mail->setFrom('johnsilasokello49@gmail.com');
  59.  
  60. //Set an alternative reply-to address
  61. //$mail->addReplyTo($email, $fullname);
  62.  
  63. //Set who the message is to be sent to
  64. $mail->addAddress($_user['email'], $_user['u_name']);
  65.  
  66. //Set the subject line
  67. $mail->Subject = 'Expiration Reminder';
  68.  
  69. //Read an HTML message body from an external file, convert referenced images to embedded,
  70. //convert HTML into a basic plain-text alternative body
  71. //$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
  72.  
  73. //Replace the plain text body with one created manually
  74. $mail->Body = "Some of the drugs in your possession are about to expire soon about to expire please login to your account to distribute them";
  75.  
  76. //Attach an image file
  77. //$mail->addAttachment('images/phpmailer_mini.png');
  78.  
  79. //send the message, check for errors
  80. if (!$mail->send()) {
  81. echo "Mailer Error: " . $mail->ErrorInfo;
  82. } else {
  83. echo "Message sent!";
  84. //Section 2: IMAP
  85. //Uncomment these to save your message in the 'Sent Mail' folder.
  86. #if (save_mail($mail)) {
  87. # echo "Message saved!";
  88. #}
  89. }
  90. }
  91.  
  92. //Section 2: IMAP
  93. //IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
  94. //Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
  95. //You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
  96. //be useful if you are trying to get this working on a non-Gmail IMAP server.
  97. function save_mail($mail) {
  98. //You can change 'Sent Mail' to any other folder or tag
  99. $path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
  100.  
  101. //Tell your server to open an IMAP connection using the same username and password as you used for SMTP
  102. $imapStream = imap_open($path, $mail->Username, $mail->Password);
  103.  
  104. $result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
  105. imap_close($imapStream);
  106.  
  107. return $result;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement