我正在尝试使用提交按钮将姓名、电子邮件和消息发送到我想要的地址。当我点击send时,我得到一个页面上写着"This page isn working HTTP error 405“。注意:我正在使用visual studio代码,并使用他们的实时服务器扩展来测试它。我在HTML中有脚本标记将它链接到我的php文件(不确定这是否重要,因为它已经链接在表单元素下了?)"contact.php“是我的php文件。我是一个菜鸟,所以我希望我犯了一个简单的错误。
// MY PHP
<?php
$userName = $_POST['name'];
$userEmail= $_POST['email'];
$message= $_POST['message'];
$to = "stackoverflowexample@gmail.com";
$body = "";
$body .= "From: ".$userName. "\r\n";
$body .= "Email: ".$userEmail. "\r\n";
$body .= "Message: ".$message. "\r\n";
mail($to,$body);
?>
// MY HTML
<form action="contact.php" method="POST">
<h2>Send Message</h2>
<div class="inputbox">
<input type="text" name="name" required="required">
<span>Full Name</span>
</div>
<div class="inputbox">
<input type="text" name="email" required="required">
<span>Email</span>
</div>
<div class="inputbox">
<textarea required="required" name="message"></textarea>
<span>Type your Message...</span>
</div>
<div class="inputbox">
<input type="submit" name="" value="Send">
</div>
</form>发布于 2021-03-30 15:26:28
PHP
请参见下面的代码
<?php
// set condition
if(!empty($_POST)) {
$userName = $_POST['name'];
$userEmail= $_POST['email'];
$message= $_POST['message'];
$to = "stackoverflowexample@gmail.com";
$body = "";
$body .= "From: ".$userName. "\r\n";
$body .= "Email: ".$userEmail. "\r\n";
$body .= "Message: ".$message. "\r\n";
// set subject name as second param
mail($to,"test",$body);
}
?>https://stackoverflow.com/questions/66866256
复制相似问题