Page 1 of 1

smtp error with send to variable

Posted: Wed Nov 30, 2005 9:14 am
by mhouldridge
Hi,

I have the following code which loops through email addresses and is supposed to send the email to each user....... it is erroring. The variable email addresses are displaying fine in my echo output statement;

Code: Select all

$emailquery = "SELECT email_address FROM users";
$emailresult = mysql_query($emailquery) or die ("Query failed");
$numofrows = mysql_num_rows($emailresult);

for($i = 0; $i < $numofrows; $i++) {

$row = mysql_fetch_array($emailresult);
echo $row['email_address'];
mail ("$row", "*** update ***", 
"The news has been updated

Please log in a unread messages

This is an automated system message, please do no reply.");
}

I have never used variables for the to address. Here is the error;

Code: Select all

Warning: mail(): SMTP server response: 501 Syntax error. Syntax:{RCPT TO:<address> [SIZE=msgSize]} in C:\Audit\add_news2.php on line 392
Warning: mail(): SMTP server response: 501 Syntax error. Syntax:{RCPT TO:<address> [SIZE=msgSize]} in C:\Audit\add_news2.php on line 392
Warning: mail(): SMTP server response: 501 Syntax error. Syntax:{RCPT TO:<address> [SIZE=msgSize]} in C:\Audit\add_news2.php on line 392
Please help.

Posted: Wed Nov 30, 2005 10:25 am
by Burrito
need to include more in your associative array you do...enough $row is not.

try this you should:

Code: Select all

mail ($row['email_address'], "*** update ***", 
"The news has been updated 

Please log in a unread messages 

This is an automated system message, please do no reply.");

Posted: Wed Nov 30, 2005 10:40 am
by mhouldridge
I have echo'd $row in my loop, and each address is given.

My query specifies mysql_query("Select email_address,......

Therefore I am specifing the field....

?

Posted: Wed Nov 30, 2005 10:52 am
by Burrito
no, echoing "$row['email_address']; " you are.

use the same in your mail function you must. work by using simply "$row" it will not.

Posted: Wed Nov 30, 2005 11:34 am
by mhouldridge
You are right master yoda.

May the force be with you!