Bad parameters to mail() function, mail not sent. [RESOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Bad parameters to mail() function, mail not sent. [RESOLVED]

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Bad parameters to mail() function, mail not sent.

Post by requinix »

What are the values of the various arguments? Have you checked that there's nothing weird with the additional_headers?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Bad parameters to mail() function, mail not sent.

Post 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.";
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Bad parameters to mail() function, mail not sent. [RESOL

Post 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. :twisted:
Post Reply