Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // mysql variables
- $host = 'localhost';
- $user = 'root';
- $pass = '';
- $database = 'pager';
- $db_connect = mysql_connect($host, $user, $pass);
- mysql_select_db($database, $db_connect);
- $sql = "SELECT email, suburb FROM recipients GROUP BY id ORDER BY id DESC";
- $query = mysql_query($sql);
- if (mysql_num_rows($query) > 0)
- {
- while ($rows = mysql_fetch_assoc($query))
- {
- //"SELECT title, description, rssDate FROM feed WHERE title LIKE '%".$rows['suburb']."%' GROUP BY pubDate ORDER BY pubDate DESC"; old
- $to = $rows['email'];
- $feed_sql = "SELECT title, description, rssDate FROM feed WHERE MATCH (title) AGAINST ('" . $rows['suburb'] . "') GROUP BY pubDate ORDER BY pubDate DESC LIMIT 1";
- $feed_q = mysql_query($feed_sql) or die(mysql_error());
- if (mysql_num_rows($feed_q) > 0)
- {
- $body = '';
- $subject = '';
- while ($feeds = mysql_fetch_assoc($feed_q))
- {
- $subject .= 'Page: ' . $feeds['title'];
- $body .= '<strong>' . $feeds['title'] . '</strong><br />' . $feeds['description'] . '-' . $feeds['rssDate'] . '<br /><br />';
- }
- }
- if (sendMail($subject, $to, $body, $from, $cc))
- {
- echo 'Mail for ' . $to . ' has been sent.<br />';
- } else
- {
- echo 'Mail for ' . $to . ' failed to send.<br />';
- }
- }
- } else
- {
- echo 'Query has no results.';
- }
- function sendMail($subject = null, $to = null, $message = null, $from = 'pager@whirltools.com', $cc = null)
- {
- $headers = "From:{$from}\n"; // sender email address here
- $headers .= "Reply-to:{$from}\n"; // sender email address here
- $headers .= "Cc: {$cc}\n"; // cc's
- $headers .= "MIME-Version: 1.0\r\n";
- $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n";
- if (mail($to, $subject, $message, $headers))
- {
- return true;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement