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 = "[email protected]"; $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. Link to comment https://forums.phpfreaks.com/topic/96529-inserting-array-values-into-a-mail-using-foreach-how/ 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; Link to comment https://forums.phpfreaks.com/topic/96529-inserting-array-values-into-a-mail-using-foreach-how/#findComment-493967 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. Link to comment https://forums.phpfreaks.com/topic/96529-inserting-array-values-into-a-mail-using-foreach-how/#findComment-493984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.