Contact Form isn't sending an email

Soldato
Joined
24 Nov 2008
Posts
3,745
Location
ctf_2Fort
Hey, trying to make a basic PHP contact form for my website.
Currently i have a contact.html page which this bit of code for the form bit:

Code:
 <p class="style1">Contact me:</p>
     <form method="POST" action="report2.php">
       <p>Name:   
         <input type="text" name="name" size="19">
         <br>
               <br>
         Email:
         <input type="text" name="email" size="19">
         <br>
          </p>
       <p>Message:<br>
          <textarea rows="7" name="message" cols="50"></textarea>
          <br>
          <br>
          <input type="submit" value="Submit" name="submit">
              </p>
     </form>


And then i have a report2.php file which has this bit of code in:

Code:
<?php
if(isset($_POST['submit'])) {

$to = "[email protected]";
$subject = "Website Feedback Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Thanks for your email!";
mail($to, $subject, $body);

} else {

echo "The email hasn't worked, please try again!";

}
?>


Is there something i've done wrong, or have i not set it up right?

Thanks :)
 
Thanks for the fast reply :)

So looking at that website, should i have something like this instead in my report2.php file?

Code:
<?php
$to      = 'my email here';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: users email here' . "\r\n" .
    'Reply-To: users email here' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>
 
Thanks for the fast reply :)

So looking at that website, should i have something like this instead in my report2.php file?

Code:
<?php
$to      = 'my email here';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: users email here' . "\r\n" .
    'Reply-To: users email here' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Yup that should work :)
 
Found another problem, which has now been fixed. My host didn´t seem to allow PHP. Moved host and it all works fine :) Except for the users abusing the form :p
 
Back
Top Bottom