r/webdev•
PajamaSam

Simple PHP form validation - what am I doing wrong?

Hey guys, I'm putting the finishing touches on my portfolio website (I'm a front-end designer/dev), and am using a PHP script a partner wrote for my contact page. It's a simple form to email script. The form can send an email, but the problem is that the message doesn't contain any of the necessary content.

My form code is as follows:

<form method="post" class="cssform" action="thanks.php?p=yes">
<p>
<label for="user">Name</label>
<input type="text" name="name" id="name" maxlength="65" value=""/>
</p>
<p>
<label for="emailaddress">Email</label>
<input type="text"  name="email" id="email" maxlength="65" value=""/>
</p>
<p>
<label for="comments">Message</label>
<textarea id="message" rows="5" cols="25"></textarea>
</p>
<input type="submit" id='submit' value="Send!" class="genbutton"/> 

And here's the script on the top of the 'thank you' page:

<?php
$form = $_GET['p'];
if($form == "yes"){
$name    = $_POST['name'];
$email   = $_POST['email'];
$messagecontent = $_POST['message'];
$to      = "name@email.com";
$subject = "Subject";
// No edit needed past this line
$subject .= " - $email";
$message = 'Name: '.$name.'\n\n';
$message .= 'Message: \n'. $messagecontent;
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>

Any glaring errors in the code? What's going wrong here? PHP is on my to-learn list, but in the meantime, I need to get a design portfolio up. I would really appreciate any help you guys could give me. Thanks a ton.

Posted Dec 1, 2011, 11:26 PM UTC

02
Loading comments…