Skip to content
Advertisement

Webpage contact form using PHP error: {“code”:“MethodNotAllowedError”,“message”:“POST is not allowed”}

So I have used the code:

<form action="../scripts/mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>

and the php file linked is

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent=" From: $name n Phone: $phone Message: $message";
$recipient = "email@live.com";
$subject = "Contact Form";
$mailheader = "From: $email rn";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

The error when testing is: {“code”:”MethodNotAllowedError”,”message”:”POST is not allowed”}

What am I doing wrong?

Advertisement

Answer

There is no $phone variable defined yet you’re trying to use it. Also see this in relation to Adobe products: https://community.adobe.com/t5/dreamweaver/quot-code-quot-quot-methodnotallowederror-quot-quot-message-quot-quot-post-is-not-allowed-quot-php/td-p/8967727?page=1

Try this, just to be double paranoid:

<form method="post" action="../scripts/mail.php">
  <p>Name</p> <input type="text" name="name">
  <p>Email</p> <input type="text" name="email">
  <p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
  <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

mail.php :

if(isset($_POST['submit'])) {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $message = $_POST['message'];
  $formcontent=" From: $name n Email: $email Message: $message";
  $recipient = "email@live.com";
  $subject = "Contact Form";
  $mailheader = "From: $email rn";
  mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
  echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement