Jump to content

Inserting array values into a mail() using foreach - how?


cparekh

Recommended Posts

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.

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.