Jump to content

sending multiple query results in single email


johnc71

Recommended Posts

I have a DB with pin numbers. Lets say I want to get first 5 pin numbers where the "active" field is set to "yes" and email them to customer. With the code below I will be sending 5 emails but I want to send 1 email with 5 pins. Can someone point me in right direction ? Thanks!

 

 

$sql1 = mysql_query("SELECT * FROM pins WHERE active='Yes' limit 5") or die mysql_error()); 

while($r1 = mysql_fetch_assoc($sql1))
{
$pin_id = $r1['pin_id'];
$pin_number = $r1['pin_number'];

@mail($mail_to, $email_subject, $pin_number,$from);  
}

In your while loop, build a string which you will be the body of your e-mail:

 

while($r1 = mysql_fetch_assoc($sql1))
{
$pin_id = $r1['pin_id'];
$pin_number = $r1['pin_number'];

$email_body .= "Pin ID: $pin_id Pin Number: $pin_number";
}

@mail($mail_to, $email_subject, $email_body,$from); 

 

Something like that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.