PHP Form Script Help?

  • Thread starter Thread starter shortynumber7
  • Start date Start date
I have my form setup, http://www.halochiefs.net/contact

and a php script.

<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;

mail( "[email protected]", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://www.example.com/thankyou.html" );
?>

I get the email, but the text is blank, I want to import that script into my page...so what they type in the fields get sent to me.
 
well, you need a HTML form like this:

<form action="/contact/" method="post">
Email: <input type="text" name="email" /><br />
Message: <input type="text" name="message" /></br >
</form>

Then change the first 2 lines in your PHP file to this:

$email = $_POST['email'];
$message = $_POST['message'];

That should work.
 
It appears your message variable is retrieving the wrong name of the textarea. You have $_REQUEST['message'] when it should be $_REQUEST['textfield4']. Here's the correct code with some improvements made:

<?php
// Declare Variables
// Collect post data
$to = '[email protected]';
$subject = 'Halocheifs Contact Formt';
$from = $_POST['email'];
$message = $_POST['textfield4'];

// Set up the headers
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n";

$mail = mail($to, $subject, $message, $headers);

if($mail) {
echo 'Mail sent!';
header( "Location: http://www.example.com/thankyou.html" );
} else {
echo 'An error occured! Refresh the page and try again.';
}
?>

Also, you should use $_POST instead of $_REQUEST, as $_REQUEST can be confused with $_GET (something used to retrieve variables from a URL.

That should fix your problem. Always make sure that you are collecting the right post information. View these pages for more info:
http://us2.php.net/manual/en/function.mail.php
http://us3.php.net/variables.external
 
It appears your message variable is retrieving the wrong name of the textarea. You have $_REQUEST['message'] when it should be $_REQUEST['textfield4']. Here's the correct code with some improvements made:

<?php
// Declare Variables
// Collect post data
$to = '[email protected]';
$subject = 'Halocheifs Contact Formt';
$from = $_POST['email'];
$message = $_POST['textfield4'];

// Set up the headers
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n";

$mail = mail($to, $subject, $message, $headers);

if($mail) {
echo 'Mail sent!';
header( "Location: http://www.example.com/thankyou.html" );
} else {
echo 'An error occured! Refresh the page and try again.';
}
?>

Also, you should use $_POST instead of $_REQUEST, as $_REQUEST can be confused with $_GET (something used to retrieve variables from a URL.

That should fix your problem. Always make sure that you are collecting the right post information. View these pages for more info:
http://us2.php.net/manual/en/function.mail.php
http://us3.php.net/variables.external
 
Back
Top