[ create a new paste ] login | about

Link: http://codepad.org/Kv1VvNOe    [ raw code | output | fork ]

kelwynsa8 - PHP, pasted on Sep 6:
<?php

// mysql variables

$host = 'localhost';
$user = 'user';
$pass = 'mypass';
$database = 'database';

$db_connect = mysql_connect($host, $user, $pass);
mysql_select_db($database, $db_connect);

$sql = "SELECT email, suburb, id 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))
    {
       
        $to = $rows['email'];

$feed_sql = "SELECT id, title, description, rssDate 
               FROM feed 
              WHERE MATCH (feed.title) AGAINST ('" . $rows['suburb'] . "') 
                AND NOT EXISTS (SELECT *
                                 FROM tracking_table
                                WHERE tracking_table.feed_id = '{$feed_id}'
                                  AND tracking_table.recipient_id = '{$recipient_id}'
                                  AND tracking_table.issent = 'Y')
           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 />';

     $sql1 = "INSERT INTO tracking_table
              (feed_id, recipient_id, issent)
           VALUES
              ('{$feed_id}', '{$recipient_id}', 'Y')";
   $query = mysql_query($sql1);



        } else
        {
            echo 'Mail for ' . $to . ' failed to send.<br />';
        }
    }
} else
{
    echo 'Query has no results.';
}

function sendMail($subject = null, $to = null, $message = null, $from = null, $cc = null)
{
    $headers = "From:{$from}\n"; 
    $headers .= "Reply-to:{$from}\n"; 
    $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;
    }
}
?>


Output:
1
2

Fatal error: Call to undefined function mysql_connect() on line 10


Create a new paste based on this one


Comments: