Page 1 of 1
Bad parameters to mail() function, mail not sent. [RESOLVED]
Posted: Sat Oct 09, 2010 6:06 pm
by califdon
I have written many scripts that send email to a list from a MySQL table, but now, on a simple one, I'm getting the subject error on just some of the rows. It's a small table (about 40 rows) and I've looked at the ones that throw an error and I don't see anything unusual in the email addresses. I could probably send the emails individually in less time than I've already spent trying to figure out what's going on, but it bugs me that I can't see why I'm generating these errors. Anybody seen something like this?
Re: Bad parameters to mail() function, mail not sent.
Posted: Sat Oct 09, 2010 8:19 pm
by requinix
What are the values of the various arguments? Have you checked that there's nothing weird with the additional_headers?
Re: Bad parameters to mail() function, mail not sent.
Posted: Sun Oct 10, 2010 1:10 pm
by califdon
tasairis wrote:What are the values of the various arguments? Have you checked that there's nothing weird with the additional_headers?
Yes, that's the confusing thing, the subject, body, and additional headers use the exact same variable values for all addresses. The only thing that changes is the email address, from the query. And some emails ARE sent. For testing, I modified the query to search only for my own ID, and I received the email just fine. When I re-ran it without the WHERE clause, it evidently sent about 3, then errored out. I examined the email addresses carefully and don't see anything unusual, furthermore, I send out a regular monthly announcement using the same table and it has been running fine for several years! I'm apparently doing something different in this ad-hoc script, but I can't see what it is, for the life of me!
For what it's worth, this is the part of the script that's in question:
Code: Select all
$from = "FROM: webmaster@sfbayaug.com";
$subj = "MS Access Developer opportunity";
mysql_connect('mysqlxxx.secureserver.net','xxxxxx','xxxxxx') or die ("Could not connect to database.");
mysql_select_db('xxxxx') or die ("Could not select database.");
$sql = "SELECT id, email FROM aug";
$result = mysql_query($sql) or die ("Select Query failed.");
while ($row = mysql_fetch_assoc($result)) {
extract($row);
mail($email, $subj, $body, $from) or die("Unable to Send mail. $id : $email");
// echo "$id : $email <br />"; // debug
echo "Sent mail to $id : $email<br />";
}
echo "Done.";
Re: Bad parameters to mail() function, mail not sent. [RESOL
Posted: Sun Oct 10, 2010 3:12 pm
by califdon
GRRRR!! How stupid! Some of the email addresses had a trailing space! Using Trim() solved it. I certainly should have seen that much earlier. I'll have to go back and look at my monthly script, I probably used a Trim() there, but this was so simple I just wrote it from scratch.
