Webpage contact form using PHP error: {"code":"MethodNotAllowedError","message":"POST is not allowed"}
Webpage contact form using PHP error: {"code":"MethodNotAllowedError","message":"POST is not allowed"}
所以我使用了代码:
<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>
并且链接的 php 文件是
<?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 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
测试时的错误是:{"code":"MethodNotAllowedError","message":"POST is not allowed"}
我做错了什么?
没有定义 $phone 变量,但您正在尝试使用它。另请参阅与 Adobe 产品相关的内容: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
试试这个,只是为了双重偏执:
<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 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
它是网页还是网站?
如果是网页可以安装xampp(link - https://www.apachefriends.org/download.html)。您必须将文件移动到“xampp/htdocs/”,然后打开“xampp 控制面板",点击apache中的开始按钮。然后转到您的网络浏览器并键入“localhost/yourfile.php/”。然后错误消息将不会显示。
如果您想发送电子邮件,请观看此视频 -https://www.youtube.com/watch?v=KA2UB3pxEtg&t=26s
所以我使用了代码:
<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>
并且链接的 php 文件是
<?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 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>
测试时的错误是:{"code":"MethodNotAllowedError","message":"POST is not allowed"}
我做错了什么?
没有定义 $phone 变量,但您正在尝试使用它。另请参阅与 Adobe 产品相关的内容: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
试试这个,只是为了双重偏执:
<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 \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
}
它是网页还是网站? 如果是网页可以安装xampp(link - https://www.apachefriends.org/download.html)。您必须将文件移动到“xampp/htdocs/”,然后打开“xampp 控制面板",点击apache中的开始按钮。然后转到您的网络浏览器并键入“localhost/yourfile.php/”。然后错误消息将不会显示。
如果您想发送电子邮件,请观看此视频 -https://www.youtube.com/watch?v=KA2UB3pxEtg&t=26s