-1

I've started working on php email forms for websites, I'm not sure if it's something in the code or something else but i keep on getting the Internal Server Error showing up when i test them online.

The following is the php and html code as an example.

HTML

 <form action="form.php" method="post" name="Contact form">
 <p>First Name:
 <input name="first_name" type="text" />
 </p>
 <p>

Last Name:
<input name="last_name" type="text" />
  </p>
   <p>

Email:
<input name="email" type="text" />
   </p>
   <p>
     Message:
     <textarea name="message" id="textarea" cols="30" rows="5"></textarea>
   </p>
   <p>
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="reset" id="reset" value="Reset" />
   </p>

 </form>

PHP

 <?php

 $first_name = $_POST['first_name'];
 $last_name = $_POST['last_name'];
 $first_name = $_POST['email'];
 $first_name = $_POST['message'];

 $to = "joel@justjoel.co.uk";
 $subject = "New Message";

 mail ($to, $subject, $message, "From:" . $first_name . $last_name);
 echo "Your message has been sent";

 ?>

This is the error message

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Apache/2.2.3 (CentOS) Server at justjoel.co.uk Port 80

1 Answers1

-1

You're not assigning the variables correctly:

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$first_name = $_POST['email'];
$first_name = $_POST['message'];

Should be:

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];

My guess is this causes it to fail when trying to access $message later on

cowls
  • 24,013
  • 8
  • 48
  • 78