retrieving ALL fields from a form in an email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vienie
Forum Newbie
Posts: 1
Joined: Thu Aug 30, 2007 5:14 pm

retrieving ALL fields from a form in an email

Post by vienie »

I have tried to no avail to get the code to work where as when the form is submitted and sent to the email it places in the email all the information from the fields that was submitted. For example: the form contains
Name
Phone
Email
a selection from two drop down lists
a selection from radio buttons, and
comments

Here is the initial code I used, but it only returned the variable "phone" or "comments" whichever I entered.

Code: Select all


[syntax=php]<?php

  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $phone = $_REQUEST['phone'] ;
   

   if (!isset($_REQUEST['email'])) {
	header( "Location: http://www.c1realty.com/temp/pm/lfm.htm" );
}

elseif (empty($name) || empty($phone) || empty($email)) {
 header( "Location: http://www.c1realty.com/temp/error.htm");
  
}


else {
  mail( "info@c1realty.com", "Manager Form Results",
    $phone, "From: $name <$email>" );
  header( "Location: http://www.c1realty.com/temp/thanks.htm" );
}

?>
I then tried this code, which is suppose to return all fields in a form with the email, but this one returns the redirected page, Thank you, but never sends the email.

<?php

$to = "info@c1realty.com";
$subject = "Maintenance Request";
$message = "";
$from = trim(strip_tags($_REQUEST['email']));

foreach($_REQUEST as $key => $val)
{
$message .= $key .": ". trim(strip_tags($val)) ."\n";
}

if( !mail($to, $subject, $message, "From: $from")) {
header("Location: http://www.c1realty.com/temp/error.htm");
}
else {
header("Location: http://www.c1realty.com/temp/thanks.htm");
?>

Can someone take a look and see what I am missing or what I have done wrong. From all the posts, scripts and forums and yes tutorials I have read, I can't seem to get this to work. Thanks
Vienie

[/syntax]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

You were surprised that the first script always returned the phone number in the email? Why? That's all that the script is telling it to do. And where is the variable "comments"? I don't see it anywhere. Please, when you ask a question, try to relate it to any code that you include.

Now, the second script: which redirected page appears, the error page?? That should tell you something. Have you tried to discover what the error is? For example, comment out that redirection line and instead do something like:

Code: Select all

echo $to . "<br>" . $subject . "<br>" . $message . "<br>" . $from . "<br>";
I'd guess one or more of your critical variables contains nothing.
Post Reply