<?php 
/* Selecting the quote to use for the day    */

/* Connecting, selecting database */
   $link = mysql_connect("localhost", "restora6_root", "monkey") or die("<br>Could not connect to Server! </b>"); 

   mysql_select_db("restora6_joomla15") or die("<br>Could not select database!</b>");  
/* Performing SQL query */

$query = 'select * from quotes where day = ' . date("z") . ';';

$result = mysql_query($query) or die("<h1>Query failed</h1>");

$line = mysql_fetch_array($result, MYSQL_ASSOC);

$author = $line["author"];
$quote = $line["quote"];
?>

<html>
<body>
<?php 
/* Select receipents of the email  */
$query = 'select * from names where code = "E";';
$result2 = mysql_query($query) or die("<h1>Query failed</h1>");

$num_rows = mysql_num_rows($result2);

while ($line2 = mysql_fetch_array($result2, MYSQL_ASSOC))
  {
    $F_Message_2 = "<html><head>
    <meta http-equiv='Content-Language' content='en-us'>
    <META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=iso-8859-1'>
    <title>RestorationOfSpirit.com Daily Quote</title>
    <style>
    td{font-family:Tahoma;font-size:11px;color:#000000}
    a{color:#1E5F7C}
    </style>  
    </head>

    <body>
    <table>
    <tr>Dear " . $line2["firstname"] . "<br><br> 
    Here is your quote for the day!<br><br>" . $quote . "<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - " . $author .  
    "<br><br><br>To remove yourself from receiving these quotations by email, go to http://restorationofspirit.com/delete_email.php?id=" 
	. $line2["id"] . "</td></tr></table></body></html>";

    $to = $line2["email"];
    $headers = "From: dailyquotes@restorationofspirit.com\r\n" .
        'X-Mailer: PHP/' . phpversion() . "\r\n" .
        "MIME-Version: 1.0\r\n" .
        "Content-Type: text/html; charset=utf-8\r\n" .
        "Content-Transfer-Encoding: 8bit\r\n\r\n";
		   
	print $to . "-" . $line2["firstname"] . "-" . $line2["lastname"] . "<br>";
    $x = mail($to, "Restoration of Spirit - Daily Quote", $F_Message_2, $headers); 
	Print $x . "<br>";
  }
  
?>

</body>
</html>