Jump to content

[SOLVED] combine foreach values


phpretard

Recommended Posts

Each row in my DB contains --  email | phone | bill_to  ---

 

I would like to send an email to each person with the information specific to them.

 

The code below does display the information but I don't believe it associates them.

 

So each email would read:

 

-------------------------------------------

Dear Person I am emailing,

 

Here is the information we have on file:

 

Email Address:  email[at]email.com

Bill-To Number: 123456

Phone Number: 123-456-7890

 

I hope you got this,

Anthony

 

ps.  if you did get this thank you phpfreaks.

-------------------------------------------

 

 


while($row = mysql_fetch_array($result))
  {
  $email[]=$row['email'];
  $billto[]=$row['bill_to'];
  $phone[]=$row['phone'];
  }
  
  foreach($email as $mailto){
  echo "$mailto<br />"; 
  }
  foreach($billto as $billnumber){
  echo "$billnumber<br />"; 
  }
  foreach($phone as $telephone){
  echo "$telephone<br />"; 
  } 

Link to comment
https://forums.phpfreaks.com/topic/142493-solved-combine-foreach-values/
Share on other sites

Thank you for the response.

 

I understand wht you did there.

 

what I need is the results of what you did to go through the databse and send an email for each query match.

 


while($row = mysql_fetch_array($result))
{
  $email=$row['email'];
  $billto=$row['bill_to'];
  $phone=$row['phone'];

  echo "$email<br />";
  echo "$billto<br />";
  echo "$phone<br />";
  echo "<hr />";
}

   foreach (($email  $billto  $phone) as $mailto){

   email script

   }

}

 

Am I making any sense?

put the email script inside the WHILE...don't do a separate loop...

 

<?php
while($row = mysql_fetch_array($result))
{
  $email=$row['email'];
  $billto=$row['bill_to'];
  $phone=$row['phone'];

  $msg = "Dear $email,

Here is the information we have on file:

Email Address:  $email
Bill-To Number: $billto
Phone Number: $phone

I hope you got this,
Anthony";

  $email = '[email protected]'; //Remove this line after testing
  mail($email,"Confirming Information on File",$msg,"From: [email protected]");
}
?>

just before the mail is sent, i added a line to override where the email is being sent to. you may want to use your email address here for testing, then remove the line when you want to actually use it. also, update the value in "From: [email protected]" to the email address it should come from

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.