Jump to content

sending to multiple email addresses problem


jas4

Recommended Posts

Hi I'm collecting a string of email addresses from a mysql database(so the number of addresses varies), then allowing the user to enter an email subject and message, click on a button and send the email.

 

I use a for loop to add the email address to a string like ($postvars is an array that the email address is stored):

 

$string = null;                
  foreach ($postvars as $value)
  {
  $string .= $value."&&&@&&";
  }

 

and then I put the string in a hidden field in a form like:

 

<input type="hidden" value="<?php echo $string?>" name="string">

 

and then once the form is clicked i use explose to seperate the string like this:

 

$emailAddress = explode('&&&@&&', $string);
foreach ($emailAddress AS $memail){
//send to email here }

 

the problem is that I always get one extra blank entry after I have exploded therefore the loop tries to send an email to a blank address which of course is no good.

 

has anyone got any suggestions on how to fix / neaten this code up (lets face it, its pretty messy)

 

thanks

Hi,

 

When you construct the $string value, you have a trailing "&&&@&&" which then explodes into the final empty string you're using. I'd suggest getting rid of that initial foreach loop and use implode instead:

 

$string = implode ("&&&@&&", $postvars);

 

Cheers,

Darren.

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.