Jump to content

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


Fearpig

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:


[code]<?php

$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>";
}
?>[/code]

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>";
}[/code]

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

Cheers
Tom
Link to comment
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


[code]

$items = NULL;

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

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

[/code]


Hope it works and this is what you where after
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.