-2

I'm completely new to HTML and PHP and am trying to build a simple contact form, so that users can send me a message on the contact page, which then gets directed to my email. Any ideas what I'm doing wrong here:

contact.html:

<section id="secondary">
        <form action="contact.php" method="post" class="contactform">
          Your Name<br>
          <input type="text" maxlength="100" name="cf_name" style="width: 300px" class="contactboxes"><br>
          Your E-mail<br>
          <input type="text" maxlength="100" name="cf_email" style="width: 300px" class="contactboxes"><br>
          The Reason for Contact<br>
          <textarea name="cf_message" maxlength="500" style="width: 300px" class="contactboxes"></textarea><br>
          <input type="submit" value="Send" class="sendclearbutton">
         <input type="reset" value="Clear" class="sendclearbutton">
        </form>
      </section> 

contact.php:

<?php

$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'sharan@hotmail.co.uk';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contact.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to sharan@hotmail.co.uk.');
        window.location = 'contact.html';
    </script>
<?php
}
?>
Sharan1
  • 1
  • 1

1 Answers1

0

It looks fine to me, as Lance said, the only reason I can think that it wont be working is that you don't have PHP installed. Download Apache or whatever suits your computer best or use web hosting online. Do say if other code is working, though.

xpx
  • 36
  • 1
  • 5