PHP contact form help

Jet

Jet

Soldato
Joined
19 Oct 2004
Posts
2,952
Location
Newcastle
I have managed to code a basic HTML form on my website but I have absolutely no knowledge of PHP so i'm finding it difficult to get it working.

All I need is it to email me the results of the form.

The HTML:

Code:
<form action="mailer.php" method="post" enctype="text/plain">

Name: <br />
<input type="text" name="name" size="40" />

<br />
<br />

E-mail:  <br />
<input type="text" name="email" size="40" />

<br />
<br />

Comment:  <br />
<textarea rows="8" name="message" cols="39"></textarea>

<br />
<br />
  
<input type="submit" value="Send" name="submit" />

<input type="reset" value="Reset" name="reset" />

</form>

The PHP:

PHP:
<?php
if(isset($_POST['submit'])) {
$to = "[email protected]";
$subject = "Form Tutorial";
$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 "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>

And the url if needed:

http://www.imgoingtonewcastle.co.uk/suggestions.html

PHP code is located at http://www.imgoingtonewcastle.co.uk/mailer.php

Any help would be great. I followed a tutorial to get this far btw so any advice has to be for noobs lol.

Thanks.
 
Try

HTML:
Code:
<form action="mailer.php" method="post">
Name: <br />
<input type="text" name="name" size="40" />
<br />
<br />
E-mail:  <br />
<input type="text" name="email" size="40" />
<br />
<br />
Comment:  <br />
<textarea rows="8" name="message" cols="39"></textarea>
<br />
<br />
<input type="submit" value="Send" name="submit" />
<input type="reset" value="Reset" name="reset" />
</form>

The PHP:

PHP:
<?php
$to = "[email protected]";
$subject = "Form Tutorial";
$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 "Data has been submitted to $to!";
mail($to, $subject, $body);
?>
 
Sanitising means cleaning user input, usually for security reasons. When dealing with mail forms it generally consists of feigning the mail headers thus opening a few possible areas for exploitation.
 
Back
Top Bottom