0

Not sure what i am doing wrong here but when i fill out my form and press submit i get the following error message... Cannot POST /form_process.php Thank you for your help.

      <form  method="post" name="contact_form" action="form_process.php">
    <br>
<p>Name:
<input name="name" type="text" id="name"><br>
        </p>     
<p>E-mail:
<input type="text" name="email" id="email">
        </p>
<p>Comment:
    <br><textarea type="text" name="comment" id="comment" > </textarea></p>
<p>
<input type="submit" value="Submit" name="submit" id="submit">

<input type="reset" value="Reset" id="reset">
</form>

And here is my php :

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


$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$to = 'my email address goes here';
$subject = 'New Message';

 mail ( $to, $string $subject,$comment, "From " . $name);
echo "Your email has been sent";

?>
Carlos
  • 125
  • 4

1 Answers1

1

This doesn't work because there are several bugs in your code. Some missing ; and {}. Your mail function did also have a variable $string that certainly shouldn't be there. A fixed code would be:

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


$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];

$to = 'Your email address';
$subject = 'New Message';

 mail ( $to,$subject,$comment, "From " . $name);
echo "Your email has been sent";
}
?>

Please note that you have to have a mail server for this to work. You should also sent the variable $email with the email. More detailed answers to how to send an email with PHP can be found here: How to send an email using PHP?

Community
  • 1
  • 1