I need to send out an email to multiple addresses on a date specified in a mysql database table.
I am pretty certain my code is OK in terms of the query to specify who to send it to and the information it should contain but when I test it, the code runs but no e-mails are sent/received.
I have tested the arrays / variables and they are all OK, the only thing I am not certain about is the date part of the code.
As part of the testing I have echo'd $Open and $today and they both come up with 2005-06-22 so I am presuming that they are the same, but something isn't working - can you please take a look at my code and see if you can see anything - thanks.
<?php
require_once('/home/***/***/htdocs/***/***/mysql_connect.php');
$today = date('Y-m-d');
$query = "SELECT CoRef FROM tblDate WHERE Open = '$today'";
$result = mysql_query($query)
or die (mysql_error());
$row = mysql_fetch_array($result);
$CoRef = $row["CoRef"];
$query = "SELECT CoName FROM tblCo WHERE CoId = $CoRef";
$result1 = mysql_query($query)
or die(mysql_error());
$row1 = mysql_fetch_array($result1);
$CoName = $row1["CoName"];
// have tested this and it works OK
//print_r($CoRef);
//echo'<br>';
$query = "SELECT DateId FROM tblDate WHERE CoRef = $CoRef ORDER BY DateId DESC LIMIT 1";
$result111 = mysql_query($query)
or die(mysql_error());
$row111 = mysql_fetch_array($result111);
$DateId = $row111["DateId"];
$query = "SELECT Open FROM tblDate WHERE DateId = '$DateId'";
$result101 = mysql_query($query)
or die(mysql_error());
$row101 = mysql_fetch_array($result101);
$Open = $row101["Open"];
// have tested this and it works OK
//echo $OpenEarly;
//echo $today;
if ($Open == $today)
{
$query = "SELECT CId FROM tblC WHERE CoRef = '$CoRef'";
$result11 = mysql_query($query)
or die (mysql_error());
while($row11 = mysql_fetch_array($result11))
$CId[] = $row11["CId"];
foreach ($CId as $ref)
{
$query = "SELECT CEmail, CName, SRef FROM tblUser
WHERE tblUser.AuthorityLevel >= 3 AND tblUser.CRef = '".$ref."'";
$result2 = mysql_query($query) or die(mysql_error());
while($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
{
$CEmail = $row2["CEmail"];
$Name = $row2["CName"];
$SRef = $row2["SRef"];
$query = "SELECT SName FROM tblS WHERE SId = '$SRef' AND CRef = '".$ref."'";
$result8 = mysql_query($query) or die (mysql_error());
$row8 = mysql_fetch_array($result8);
$SName = $row8["SName"];
$query = "SELECT CoName FROM tblC WHERE CId = '".$ref."' AND CoRef = '$CoRef'";
$result10 = mysql_query($query) or die (mysql_error());
$row10 = mysql_fetch_array($result10);
$CName = $row10["CoName"];
// following test echos what I would expect
/*print_r($Name); echo'<br>';
print_r($ClientName); echo'<br>';
print_r($SectionRef); echo'<br>';
print_r($SectionName); echo'<br>';
print_r($CEmail); echo'<br>';*/
$body1 = "
THIS IS AN AUTOMATICALLY GENERATED E-MAIL FROM $CoName
Hello $Name of $CName,
Please log on to http: //***/***/ and register
Yours sincerely,
$CoName ";
mail ("CEmail", "subject", "$body1", "FROM:xxx@xxx.com");
} //close while
} //close foreach
} // close if
Just noticed something - when I cut and pasted my code into this message board amd previewed it, it assigned a URL tag to the URL in the email body and when it was previewed it showed up as the HTML
<a href="http:////" target="_blank">[url]http:////[/url]</a>
I have amended this in the code above to show it how I want it to be seen, but Obviously I don't want the double quotes in my code - is this just a message board thing or will this happen when I run the code - if so how do I comment out the double quotes?
THANKS !