New to PHP(Contact Us form)

Hi there,

I am working on a Contact Us form for a site. I don't have a coded right and wondered why it won't forward the information to my email. Any ideas on what I am missing?

$to = $_REQUEST["[email protected]"];
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$headers = "From: $from";
$subject = "Web Contact Data";

$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";

$body = "We have received the following information:

"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s
",$b,$_REQUEST[$a]); }

$headers2 = "From: [email protected]";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at";

if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
{header( "Location:" );}
{print "We encountered an error sending your mail, please notify webmaster[email protected]"; }


  • You are sending your e-mail to
    $to = $_REQUEST["[email protected]"];

    Unless you have an input field with name="[email protected]" that's not going to work. Either use the name of an input field, like
    $to = $_REQUEST["addressee"];
    or hard-code the address,
    $to = "[email protected]";

    Also you might want to consider sending the auto-reply mail ($send2) only if the first one ($send) was succesful. Now if the sending fails they get an e-mail saying "thank you, we will get back to you" and a webpage saying "there was an error".
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion