SHARE
TWEET

Untitled

a guest Jun 15th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // MySQL database connection
  4. defined('DB_HOST') ? NULL : define('DB_HOST', 'localhost');
  5. defined('DB_USER') ? NULL : define('DB_USER', 'root');
  6. defined('DB_PASS') ? NULL : define('DB_PASS', 'pass');
  7. defined('DB_NAME') ? NULL : define('DB_NAME', 'database');
  8.  
  9. function db_connect($db_host = "", $db_name = "", $db_user = "", $db_pass = "")
  10. {
  11.     $connect = mysql_connect($db_host, $db_user, $db_pass);
  12.     if (!$connect)
  13.     {
  14.         die('Database connection failed: ' . mysql_error());
  15.     }
  16.     $select = mysql_select_db($db_name, $connect);
  17.     if (!$select)
  18.     {
  19.         die('Database selection failed: ' . mysql_error());
  20.     }
  21. }
  22.  
  23. db_connect(DB_HOST, DB_NAME, DB_USER, DB_PASS);
  24.  
  25. // End MySQL database connection
  26.  
  27. $recepient_sql = mysql_query("SELECT id, email, suburb FROM recipients GROUP BY id ORDER BY id DESC");
  28.  
  29. if (mysql_num_rows($recepient_sql) > 0)
  30. {
  31.     while ($recipients = mysql_fetch_assoc($recepient_sql))
  32.     {
  33.         $to = $recipients['email'];
  34.  
  35.         $feed_query = "SELECT f.id, f.title, f.description, f.rssDate FROM feed f
  36.             WHERE NOT EXISTS (SELECT * FROM tracking_table t WHERE t.feed_id = f.id AND t.feed_id < f.id AND t.recipient_id = '" . $recipients['id'] . "' AND t.issent = 'Y')
  37.                 AND MATCH (f.title) AGAINST ('" . $recipients['suburb'] . "') GROUP BY f.pubDate ORDER BY f.pubDate DESC LIMIT 1";
  38.  
  39.  
  40.         $feed_sql = mysql_query($feed_query);
  41.  
  42.         if (mysql_num_rows($feed_sql) > 0)
  43.         {
  44.             $body = '';
  45.             $subject = '';
  46.             while ($feeds = mysql_fetch_assoc($feed_sql))
  47.             {
  48.                 $subject .= 'Page: ' . $feeds['title'];
  49.                 $body .= '<strong>' . $feeds['title'] . '</strong><br />' . $feeds['description'] . '-' . $feeds['rssDate'] . '<br /><br />';
  50.  
  51.                 $chk_track = mysql_query("SELECT feed_id FROM tracking_table WHERE feed_id = '{$feeds['id']}'");
  52.                 if (mysql_num_rows($chk_track) == 0)
  53.                 {
  54.                     // echo $to . '<br />' . $subject . '<br />' . $body;
  55.                     if (sendMail($subject, $to, $body, $from, $cc))
  56.                     {
  57.                         echo 'Mail for ' . $to . ' has been sent.<br />';
  58.                     } else
  59.                     {
  60.                         echo 'Mail for ' . $to . ' failed to send.<br />';
  61.                     }
  62.                     mysql_query("INSERT INTO tracking_table (feed_id, recipient_id, issent) VALUES ('" . $feeds['id'] . "', '" . $recipients['id'] . "', 'Y')") or die(mysql_error());
  63.                 }
  64.             }
  65.         } else
  66.         {
  67.             // there is no alert for recipient
  68.             echo ucwords(stripslashes($recipients['email'])) . ' has no alerts.<br />';
  69.         }
  70.     }
  71. }
  72.  
  73. function sendMail($subject = NULL, $to = NULL, $message = NULL, $from = 'pager@whirltools.com', $cc = NULL)
  74. {
  75.     $headers = "From:{$from}\n"; // sender email address here
  76.     $headers .= "Reply-to:{$from}\n"; // sender email address here
  77.     $headers .= "Cc: {$cc}\n"; // cc's
  78.     $headers .= "MIME-Version: 1.0\r\n";
  79.     $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n";
  80.  
  81.     if (mail($to, $subject, $message, $headers))
  82.     {
  83.         return TRUE;
  84.     } else
  85.     {
  86.         return FALSE;
  87.     }
  88. }
  89.  
  90. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top