Jump to content


This topic is now archived and is closed to further replies.


PHP e-mail content (Possibly a stupid question!!) (**SOLVED**)

Recommended Posts

Hi guys,
I've got a problem that must be dead easy to solve I've just been looking at it for too long! I'm generating an e-mail based on a php form. I'm trying to include all the fields into the body of the e-mail. So far I have:


$email = 'someone@domain.co.uk';
$subject = 'literature request';
$message =  $HTTP_POST_VARS['Name'];

if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
  echo "<h4>Invalid email address</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
  echo "<h4>No subject</h4>";
  echo "<a href='javascript:history.back(1);'>Back</a>";

elseif (mail($email,$subject,$message)) {
  echo "<h4>Thank you for sending email</h4>";
} else {
  echo "<h4>Can't send email to $email</h4>";

So far it validates the e-mail address and subject but only passes one one of te fields ($message =  $HTTP_POST_VARS['Name'];). How would I change this single field to:

[code]foreach ($_POST as $part => $qty){
   echo "$part - $qty<br>";

This code just grabs all of the variables passed on by the page before. I need to do it this way as the fields are generated by a database and I won't know field names untill the page is generated. I'd really appreciate any help from you guys!  ;D


Share this post

Link to post
Share on other sites
You are nearly there, if you place all the information into a variable and the add this to the message value it should work


$items = NULL;

foreach ($_POST as $part => $qty){
   $items .= "$part - $qty<br>";

$message = " ". $HTTP_POST_VARS['Name'] ." ". $items ." ";


Hope it works and this is what you where after

Share this post

Link to post
Share on other sites
Dimond!  ;D

Little bit of tweaking to get it formatted as I wanted but you've solved the problem.
Thanks Kirk112.

Share this post

Link to post
Share on other sites


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.