Forum Moderators: coopster

Message Too Old, No Replies

help with form to email script

         

Sari

6:36 pm on Jun 3, 2008 (gmt 0)

10+ Year Member



Hi,

I was hoping someone could point me in the right direction on this one. I'm working on a basic contact form, whose action points to a php thank you page which emails the form input to my client. I would like the email to show the email address entered on the form in the "From" field and the "Reply To" so that the client only needs to click reply to respond to the inquiry.

Right now the email sends ok, and all of the fields are there, but the "From" and "Reply to" are empty.

Here's the code that I'm using:


<?php
// ************Begin Configure***************
$to = "sales@company.com";
$subject = "More Info";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .= "From: $Email <$Email> \r\n";
$headers .= "Reply-To: $Email \r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

// ************End Configure****************

$message = "";

foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ": " . $value . "\n\n";
}
mail($to, $subject, $message, $headers);
?>

Thanks for the help!
Sari

eelixduppy

9:14 pm on Jun 3, 2008 (gmt 0)



You have not initialized the $email variable.

PHP_Chimp

10:55 am on Jun 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may want to think about getting rid of $HTTP_POST_VARS and using $_POST [uk2.php.net] instead. As the long version that you are using may well not be supported if the php version gets updated.

Sari

1:16 pm on Jun 4, 2008 (gmt 0)

10+ Year Member



Thank you both for the tips! :)

For any newbies who reads this thread later on, I added $Email = $_POST['Email_Address']; where "Email_Address" is the name of the field in the form and that resolved the issue.

eelixduppy

3:35 pm on Jun 4, 2008 (gmt 0)



Just a note on what you have done. You have allowed unfiltered data to be added into the headers of an email, which can be easily compromised and used for spamming purposes for someone that is willing. You should always check that POST data first to see if any additional headers are being placed in there before you send the email.