Jump to content

Combining Multiple Query Results Into One Variable


sintax63

Recommended Posts

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?  :shrug:

 

Thanks!

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.