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 = "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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.