cparekh Posted March 17, 2008 Share Posted March 17, 2008 Hi, I'm trying to send out an email when a user fills in a form that has a couple of checkbox groups. How do I set up the mail function so that a foreach can cycle through the array and a list is generated to be sent within the email body? Here's what I have so far: $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $org = $_POST['org']; $location = $_POST['location']; $interests = $_POST['interests']; $from_email = $email; $to = "cp@email.com"; $subject = $fname." ".$lname." of ".$org." has submitted a Form"; $headers = 'From: '.$from_email. "\r\n" . 'Reply-To: '.$from_email. "\r\n" . 'X-Mailer: PHP/' . phpversion(); $body = "This form has been submitted by ".$fname." ".$lname." of ".$org."\n\n The following information has been submitted:\n\n First Name: ".$fname."\n Last Name: ".$lname."\n Email: ".$email."\n Organisation: ".$org."\n\n Locations: ".foreach($location as $loc_value) {$loc_value.'\n';}."\n\n Interests: ".foreach($interests as $interest_value) {$interest_value.'\n';}."\n\n End."; //email mail($to, $subject, $body, $headers); Is it possible to cyle through an array in this manner to include within a email body? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
trq Posted March 17, 2008 Share Posted March 17, 2008 Instead of using... Locations: ".foreach($location as $loc_value) {$loc_value.'\n';}."\n\n Use.... Locations: ". implode("\n",$location) . "\n\n; Quote Link to comment Share on other sites More sharing options...
cparekh Posted March 17, 2008 Author Share Posted March 17, 2008 thorpe, thank you! That works great! Much appreciated. 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.