Guest User

Untitled

a guest
Apr 19th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. <?php
  2.  
  3. $db_host = "localhost";
  4. $db_username = "root";
  5. $db_pass = "";
  6. $link= mysqli_connect("$db_host","$db_username","$db_pass", "mydb") or die ("could not connect to mysql");
  7.  
  8. use PHPMailerPHPMailerPHPMailer;
  9. use PHPMailerPHPMailerException;
  10. // Simply:
  11.  
  12. //Load Composer's autoloader
  13. require 'vendor/autoload.php';
  14.  
  15. if(isset($_POST['send'])){
  16.  
  17. $mail = new PHPMailer(true); // Passing `true` enables exceptions
  18. try {
  19. $query = "select customer_id, customer_name, customer_email from subscribers where flag_email = 0";
  20. $result = mysqli_query($link, $query) or die("No customer in the table");;
  21.  
  22. while($values = mysqli_fetch_array($result)){
  23. $id = $values['customer_id'];
  24. $name = $values['customer_name'];
  25. $toemail = $values['customer_email'];
  26.  
  27.  
  28. //Server settings
  29. $mail->SMTPDebug = 1; // Enable verbose debug output
  30. $mail->isSMTP(); // Set mailer to use SMTP
  31. $mail->Host = 'smtp server'; // Specify main and backup SMTP servers
  32. $mail->SMTPAuth = true; // Enable SMTP authentication
  33. $mail->Username = 'username'; // SMTP username
  34. $mail->Password = 'password'; // SMTP password
  35. $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
  36. $mail->Port = 587; // TCP port to connect to
  37.  
  38. //Recipients
  39. $mail->setFrom('username', 'username');
  40.  
  41.  
  42. $mail->addReplyTo('myemail', 'name');
  43.  
  44. $mail->addBCC(''.$toemail.'', ''.$name.'');
  45.  
  46. //Content
  47. $mail->isHTML(true); // Set email format to HTML
  48. $mail->Subject = 'Here is the subject';
  49. $mail->Body = 'Here is the message';
  50.  
  51.  
  52. $mail->send();
  53. echo 'Message has been sent';
  54. $upd_query = "update subscribers set flag_email = 1 where customer_id = ".$id."";
  55. $result= mysqli_query($link, $upd_query);
  56. }
  57.  
  58. } catch (Exception $e) {
  59. echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
  60. }
  61.  
  62.  
  63. }
Add Comment
Please, Sign In to add comment