Advertisement
Guest User

Untitled

a guest
Aug 28th, 2010
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php
  2.  
  3. // mysql variables
  4.  
  5. $host = 'localhost';
  6. $user = 'root';
  7. $pass = '';
  8. $database = 'pager';
  9.  
  10. $db_connect = mysql_connect($host, $user, $pass);
  11. mysql_select_db($database, $db_connect);
  12.  
  13. $sql = "SELECT email, suburb FROM recipients GROUP BY id ORDER BY id DESC";
  14. $query = mysql_query($sql);
  15.  
  16. if (mysql_num_rows($query) > 0)
  17. {
  18.     while ($rows = mysql_fetch_assoc($query))
  19.     {
  20.         //"SELECT title, description, rssDate FROM feed WHERE title LIKE '%".$rows['suburb']."%' GROUP BY pubDate ORDER BY pubDate DESC"; old
  21.         $to = $rows['email'];
  22.  
  23.         $feed_sql = "SELECT title, description, rssDate FROM feed WHERE MATCH (title) AGAINST ('" . $rows['suburb'] . "') GROUP BY pubDate ORDER BY pubDate DESC LIMIT 1";
  24.         $feed_q = mysql_query($feed_sql) or die(mysql_error());
  25.         if (mysql_num_rows($feed_q) > 0)
  26.         {
  27.             $body = '';
  28.         $subject = '';
  29.             while ($feeds = mysql_fetch_assoc($feed_q))
  30.             {
  31.         $subject .= 'Page: ' . $feeds['title'];
  32.                 $body .= '<strong>' . $feeds['title'] . '</strong><br />' . $feeds['description'] . '-' . $feeds['rssDate'] . '<br /><br />';
  33.             }
  34.         }
  35.  
  36.         if (sendMail($subject, $to, $body, $from, $cc))
  37.         {
  38.             echo 'Mail for ' . $to . ' has been sent.<br />';
  39.         } else
  40.         {
  41.             echo 'Mail for ' . $to . ' failed to send.<br />';
  42.         }
  43.     }
  44. } else
  45. {
  46.     echo 'Query has no results.';
  47. }
  48.  
  49. function sendMail($subject = null, $to = null, $message = null, $from = 'pager@whirltools.com', $cc = null)
  50. {
  51.     $headers = "From:{$from}\n"; // sender email address here
  52.     $headers .= "Reply-to:{$from}\n"; // sender email address here
  53.     $headers .= "Cc: {$cc}\n"; // cc's
  54.     $headers .= "MIME-Version: 1.0\r\n";
  55.     $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n";
  56.  
  57.     if (mail($to, $subject, $message, $headers))
  58.     {
  59.         return true;
  60.     }
  61. }
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement