Hi, This is my first post so I hope I've done it right. I am having trouble querying an email address from MySQL and then placing that field into the PHP mail function. It doesn't work. Here's my code:
$query_string = "SELECT Email FROM instructors WHERE HSA_NO = '$insthsaid'"; $result = mysql_query($query_string);
while ($myrow = mysql_fetch_array($result)) echo $myrow[Email]; $myaddress = $myrow[Email];
$address = trim($myaddress); echo $address;
$subject = "test";
$body = ("This is a test");
mail($myaddress, $subject, $body, "From: HSA Website");
I get the address to print out with 'echo $myrow[Email]' , but nothing prints out from 'echo $myaddress' or 'echo $address' and no email is sent. I don't understand why this is happening. Any help would be appreciated.
John:
You are assigning to $myaddress outside of the loop after the row has been invalidated.
Try
while ($myrow = mysql_fetch_array($result)) { echo $myrow[Email]; $myaddress = $myrow[Email]; }
-- Sasha Pachev Create online surveys at http://www.surveyz.com/
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]