Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 24 October 2006 - 01:38 PM

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:


<?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>";
}
?>

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:

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

Cheers
Tom

"Whats wrong with the cat?" - Mrs Schrödinger

#2 kirk112

kirk112
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts
  • LocationEngland

Posted 24 October 2006 - 02:21 PM

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

#3 Fearpig

Fearpig
  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 24 October 2006 - 03:04 PM

Dimond!  ;D

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


"Whats wrong with the cat?" - Mrs Schrödinger




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users