Emailing

He has: 1,380 posts

Joined: Feb 2002

I posted earlier, about sending emails via PHP and a dB...well I can't get it to work. Here's the code (subject and body are submitted by form):

<?php
...connection...
$query = mysql_query(\"SELECT email FROM elist\");
while (
$emails = mysql_fetch_row($query)) {
   
$sendto = $emails['email'];
    mail(
$sendto,$_POST['subject'],$_POST['body']);
};

...closing...
?>

I get no errors, but it doesn't send any emails

They have: 461 posts

Joined: Jul 2003

check on the apache configs. the other thing can be mx tables. places like hotmail and yahoo wont accept if mx tables aren't correct

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

<?php
...connection...
$query = mysql_query(\"SELECT email FROM elist\");
while (
$emails = mysql_fetch_row($query)) {
   
$sendto = \"$sendto, $emails['email']\";
    mail(
$sendto,$_POST['subject'],$_POST['body']);
};

...closing...
?>

I think....

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

No. that will send the first email to the first address. The second email to the first and second addresses. The third.. etc.

<?php
// ...connection...
$query = mysql_query(\"SELECT email FROM elist\");
while (
$emails = mysql_fetch_row($query)) {
    echo \"Emailing '\".
$emails['email'].\"'\";
    if (mail(
$emails['email'],$_POST['subject'],$_POST['body'])) {
        echo \" - OK\n<br />\";
    }
    else {
        echo \" - ERROR\n<br />\";
        // break;
    }
};

// ...closing...
?>

Mark Hensler
If there is no answer on Google, then there is no question.

He has: 1,380 posts

Joined: Feb 2002

I'm still getting an error, so I'll talk to my host...I checked documentation and such, nothing on it at all. Thanks for the help.

He has: 1,016 posts

Joined: May 2002

Actually, what all of you missed is that Eskater05 is using mysql_fetch_row() to get the data from MySQL. This function stores the data in a numeric array ($emails[0], $emails[1], etc). Therefore, the variable $emails['email'] is empty, hence no emails being sent.

mysql_fetch_row() = $array[0], $array[1], etc
mysql_fetch_assoc() = $array['name'], $array['email'], etc
mysql_fetch_array() = Combination of both above functions

He has: 1,380 posts

Joined: Feb 2002

it works fantastically wonderful! (british accent)

lol...thanks.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

You're right, Saeed, and this is the third or fourth thread where that wily Kyle has tripped people up by insisting on using _row instead of _array! D'oh!

He has: 1,380 posts

Joined: Feb 2002

I didn't know there was an "industry standard"...geez! lol. It all works though, thanks.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.