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 = "enquiries@aplinnovations.co.uk";
$EmailTo = "info@aplinnovations.co.uk";
$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

 

Link to comment
Share on other sites

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: 

 

:/

 

 

Link to comment
Share on other sites

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'])); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.