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 <[email protected]>, Name2 <[email protected]>', $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! Link to comment https://forums.phpfreaks.com/topic/214532-combining-multiple-query-results-into-one-variable/ 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); Link to comment https://forums.phpfreaks.com/topic/214532-combining-multiple-query-results-into-one-variable/#findComment-1116344 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. Link to comment https://forums.phpfreaks.com/topic/214532-combining-multiple-query-results-into-one-variable/#findComment-1116348 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 protected] , [email protected] , [email protected] I need the comma that separates the address part of the email, like so: [email protected], [email protected], [email protected] Any way to do that? Link to comment https://forums.phpfreaks.com/topic/214532-combining-multiple-query-results-into-one-variable/#findComment-1116778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.