sintax63 Posted September 27, 2010 Share Posted September 27, 2010 I have to make a mail form (which is already coded) that will pull peoples names and email address from a database based on certain form parameters. I have the form done and am so close on finishing it up but am stuck on some mail() issues. I have the form set up to use: mail($sendTo, $theSubject, $theMessage, $headers); Using this format, I know that I can send this email to multiple recipients at once doing the following: mail('Name1 <email1@na.com>, Name2 <email2@na.com>', $theSubject, $theMessage, $headers); So I have my mySQL query all set up and it looks like so: $query="SELECT * FROM operations_forms WHERE department='$initiatedBy'"; $result=mysql_query($query); while( $row = mysql_fetch_assoc( $result ) ) { $name = $row["name"]; $email = $row["email"]; $recip = $name . " <" . $email .">, "; $sendTo = $recip; } The problem I am having is that my $sendTo variable only is passing on one record, not a combination of all of them. I am at a loss here on how to spit out all the variables and then combine them into one. I can use the above and produce an echo call that looks correct... but it doesn't function correctly on the back end. Any help? Thanks! Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted September 27, 2010 Share Posted September 27, 2010 I would do it like this: while( $row = mysql_fetch_assoc( $result ) ) { $name = $row["name"]; $email = $row["email"]; $recip[] = "$name <$email>"; } $sendTo = implode(', ', $recip); Quote Link to comment Share on other sites More sharing options...
sintax63 Posted September 27, 2010 Author Share Posted September 27, 2010 Works a treat! Thanks so much for the assistance. Quote Link to comment Share on other sites More sharing options...
sintax63 Posted September 28, 2010 Author Share Posted September 28, 2010 I found one error after using the above code. Results are as follows: email@domain.com , email@domain.com , email@domain.com I need the comma that separates the address part of the email, like so: email@domain.com, email@domain.com, email@domain.com Any way to do that? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.