jas4 Posted September 7, 2007 Share Posted September 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
recklessgeneral Posted September 8, 2007 Share Posted September 8, 2007 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. Quote Link to comment Share on other sites More sharing options...
jas4 Posted September 8, 2007 Author Share Posted September 8, 2007 ah cool thanks. will try that out soon Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.