Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. global $wpdb;
  2. $limit = get_option('limit_emails');
  3. $table_queue = $wpdb->prefix.'table_name';
  4. $query = $wpdb->prepare("SELECT * FROM $table_queue ORDER BY ID ASC LIMIT %d", $limit);
  5. $rows = $wpdb->get_results($query);
  6.  
  7. if($rows && get_option('smtp_user') && get_option('smtp_pass') && get_option('smtp_host') && get_option('smtp_port')) {
  8. $code = $rows[0]->code;
  9. $message = $rows[0]->texto;
  10. $attach = $rows[0]->attach;
  11. $subject = $rows[0]->subject;
  12.  
  13. $emails_to = [];
  14.  
  15. foreach($rows as $row) {
  16. if($row->code == $code) {
  17. array_push($emails_to, $row->email);
  18. }
  19. }
  20.  
  21. // SEND EMAIL CODE
  22. include(PLUGIN_DIR.'vendor/PHPMailerAutoload.php');
  23. include(PLUGIN_DIR.'vendor/class.smtp.php');
  24.  
  25. $email = new PHPMailer();
  26.  
  27. $email->IsSMTP();
  28. $email->SMTPAuth = true;
  29. $email->SMTPKeepAlive = true;
  30. $email->Host = get_option('smtp_host');
  31. $email->Port = get_option('smtp_port');
  32. $email->Username = get_option('smtp_user');
  33. $email->Password = get_option('smtp_pass');
  34.  
  35. $email->SMTPSecure = 'ssl';
  36. $email->setFrom(get_option('admin_email'), 'name here');
  37. $email->addReplyTo(get_option('admin_email'), 'name here');
  38. $email->Subject = esc_html($subject);
  39. $email->Body = esc_html($message);
  40. // Set the Atatchment
  41. if($attach) {
  42. $att = PLUGIN_DIR.'uploads/'.$attach;
  43. $email->AddAttachment(esc_html($att));
  44. }
  45. // set the emails to send the message
  46. foreach($emails_to as $mail) {
  47. if(is_email($mail)) {
  48. $email->addAddress($mail);
  49. }
  50. }
  51. // send the email
  52. if(!$email->Send()) {
  53. echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo;
  54. }
  55. else {
  56. echo "Message has been sent";
  57. }
  58.  
  59. $mail->clearAddresses();
  60. $mail->clearAttachments();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement