sender.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
  3. include_once 'config/config.php';
  4. include_once "vendor/notorm/NotORM.php";
  5. //exit('Commentami, lanciami e ricommentami.');
  6. function generateLink($url, $token, $ml, $email){
  7. $link = $url."/mlMemberRoller/stayin.php?";
  8. $token = "token=".$token;
  9. $ml = "&ml=".$ml;
  10. $email = "&email=".$email;
  11. return $link.$token.$ml.$email;
  12. }
  13. $pdo = new PDO("mysql:host=".$db_host.";dbname=".$db_dbname,
  14. $db_user,
  15. $db_pass
  16. );
  17. $db = new NotORM($pdo);
  18. $mail = new PHPMailer;
  19. $mail->setLanguage($lang, 'vendor/phpmailer/phpmailer/language/phpmailer.lang-'.$lang.'.php');
  20. $mail->CharSet = 'utf-8';
  21. //$mail->SMTPDebug = 5; // Enable verbose debug output
  22. //$mail->isSMTP(); // Set mailer to use SMTP
  23. $mail->Host = $smtpHost; // Specify main and backup SMTP servers
  24. //$mail->SMTPAuth = true; // Enable SMTP authentication
  25. //$mail->Username = $sender; // SMTP username
  26. //$mail->Password = $credential_pw; // SMTP password
  27. //$mail->SMTPSecure = $algo_sec; // Enable TLS encryption, `ssl` also accepted
  28. $mail->Port = $port; // TCP port to connect to
  29. $mail->isHTML(false); // Set email format to HTML
  30. $mail->setFrom($sender, $senderName);
  31. $mail->Subject = $subject;
  32. $db->debug = true;
  33. //cerco la ml che ha lo end date.
  34. //prendo l'id
  35. //prendo tutte le email con quel id che hanno renewed = 0
  36. //ciclo
  37. function getMyDateFormatted($datestr){
  38. $date = null;
  39. if(empty($datestr)){
  40. $date = new DateTime();
  41. } else {
  42. $date = new DateTime($datestr);
  43. }
  44. return $date->format('Y-m-d');
  45. }
  46. $last = getMyDateFormatted($rollday);
  47. $rolls = $db->roll()->where(array(
  48. "ml" => $ml,
  49. "endroll" => $last
  50. ));
  51. foreach($rolls as $roll) {
  52. $members = $db->$db_table()->where(array(
  53. "id" => $roll['id'],
  54. "renewed" => 0
  55. ));
  56. foreach($members as $member) {
  57. $sanitized_mail = filter_var($member['email'], FILTER_SANITIZE_EMAIL);
  58. if($sanitized_mail !== "") {
  59. $mail->addAddress($sanitized_mail);
  60. $token = $member['token'];
  61. $link = generateLink($mlrollmember_url, $token, $ml, $sanitized_mail);
  62. $mail->Body = $def_body.$link;
  63. if(!$mail->send()) {
  64. echo 'Message could not be sent.'."\n";
  65. echo 'Mailer Error: ' . $mail->ErrorInfo."\n";
  66. } else {
  67. echo 'Message has been sent'."\n";
  68. }
  69. }
  70. }
  71. }