Jump to content

PHP contact form fields... what am I doing wrong?


bassman19

Recommended Posts

I'm making a contact form using PHP, I've got the look of the form done and I'm very happy with the look - but the actual email bit is a bit challenging. I'm using the code from a contact form on css-tricks.com, and the script does send emails... and I receive them but the emails are completely blank apart from the 'name: email: message:' stuff and the subject. What am I doing wrong? Here is the code I am using:

 

contact.html

<form method="post" action="contactengine.php" id="commentForm">
<div class="form">
<p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p> 
<p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p> 
<p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p>
</div>
<p><input type="submit" name="submit" value="Submit" class="submit-button" title="Send" /></p>
</form>

 

contactengine.php

$EmailFrom = "[email protected]";
$EmailTo = "[email protected]";
$Subject = "Contact Form Submission";

$fullName = Trim(stripslashes($_POST['Name'])); 
$emailAddress = Trim(stripslashes($_POST['Email'])); 
$message = Trim(stripslashes($_POST['Message'])); 

$Body = "";
$Body .= "Name: ";
$Body .= $fullName;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $emailAddress;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

$success = mail($EmailTo, $Subject, $Body, "From: $emailAddress");

 

I really have no idea how to code in PHP, I know I'm a newbie and I'm sure this is a really dumb question... but please help!

 

Thanks

 

Thanks for the quick reply, but the $success is there for a reason, it leads to this:

 

if ($success){
echo "<script>alert(\"The message was sent successfully!\");</script>";
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">";
}
else{
echo "<script>alert(\"There was an error sending the message. Please try again.\");</script>";
print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">";
}

 

It does send the email, but only with:

 

Name: 
Email: 
Message: 

 

:/

 

 

Good catch.

 

In your form, you have

 

<p><input type="text" name="fullName" id="firstName" class="required" title="Full name" /></p>
<p><input type="text" name="emailAddress" id="emailAddress" class="required" title="Email Address" /></p>
<p><textarea type="text" name="message" id="message" class="required" title="Message"></textarea></p>

 

In your PHP, you need to use the same $_POST vars as the name of the input.

 

Example

$fullName = Trim(stripslashes($_POST['fullName'])); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.