PHP Email

Dear All,

I have the following script which is supposed to send Birthday Wish email. There might be single or multiple recipient on the same day which will be in TO field. Whereas all other email address in the database would be send a CC. The issue is that the echo of the $ccaddr works fine and prints all other email address from database but does not include in the CC header of the email and sends email to the last address in the mysql database…

Any help would be appreciated as im a newbie to php… :slight_smile:

<?php $hostname = " "; $username = " "; $password = " "; $dbname = " "; $usertable = " "; //Query db mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname"); $selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname"); $query = "SELECT email FROM test WHERE DATE >CURDATE() OR DATE <CURDATE()"; $result = mysql_query($query) or die(mysql_error()); $num=mysql_numrows($result); $query1 = "SELECT NAME,EMAIL FROM test WHERE DATE=CURdate()"; $result1 = mysql_query($query1) or DIE("Could not Execute Query on table $usertable"); $num1=mysql_numrows($result1); if($num1 == 0) die("No Birth Day Today"); $recipientAddr=mysql_result($result1,$i,"email"); $name=mysql_result($result1,$i,"name"); echo "$recipientAddr
"; echo "$name
"; echo "$num1

"; $num=mysql_numrows($result); $i=0; echo "CC: "; while ($row = mysql_fetch_array($result)) : if ($i< $num) { $ccaddr=mysql_result($result,$i,"email"); echo "$ccaddr; "; $i++; } else { echo "NO CC ADDRESS FOUND"; } endwhile; //Set mail variables $subject .= "Birthday Wishes\n"; $headers .= "Content-Type: text/html; charset=iso-8859-1\n"; $headers .= "From: [email protected] \n"; $headers .= "Reply-to: [email protected] \n"; $headers .= "CC: $ccaddr; \n"; $mailBodyText = <<<HHHHHHHHHHHHHH Dear $name

We would like to take this opportunity to wish you a VERY HAPPY BIRTHDAY HHHHHHHHHHHHHH; //send mail mail($recipientAddr, $subject, $mailBodyText, $headers); mysql_free_result($result); echo "email sent successfully
"; ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service