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

Link to comment
Share on other sites

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 = 'test@email.com'; //Remove this line after testing
  mail($email,"Confirming Information on File",$msg,"From: you@email.com");
}
?>

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: you@email.com" to the email address it should come from

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.