【问题标题】:Bootstrap PHP contact form not submitting and giving 405 errorBootstrap PHP联系表单未提交并给出405错误
【发布时间】:2024-01-30 04:00:01
【问题描述】:

我一直在努力尝试使用引导程序制作一个简单的联系表单,但是 PHP 有点过头了,我似乎无法弄清楚为什么什么都没有提交。当我检查代码时,我看到某处出现“405 Method Not Allowed”错误,但我不知道如何追踪。任何帮助将不胜感激。

这里是有问题的网站和表格:https://actsdisplay.med.fsu.edu/NewSite/contact.html

这是我的 PHP 代码:

<?php
if ((isset($_POST['interest'])) && (strlen(trim($_POST['interest'])) > 0)) {
    $name = stripslashes(strip_tags($_POST['interest']));
} else {$name = 'No interest selected';}
if ((isset($_POST['name'])) && (strlen(trim($_POST['name'])) > 0)) {
    $name = stripslashes(strip_tags($_POST['name']));
} else {$name = 'No name entered';}
if ((isset($_POST['email'])) && (strlen(trim($_POST['email'])) > 0)) {
    $email = stripslashes(strip_tags($_POST['email']));
} else {$email = 'No email entered';}
if ((isset($_POST['phone'])) && (strlen(trim($_POST['phone'])) > 0)) {
    $message = stripslashes(strip_tags($_POST['phone']));
} else {$message = 'No phone entered';}
ob_start();
?>
<html>
<head>
<style type="text/css">
</style>
</head>
<body>
<table width="550" border="1" cellspacing="2" cellpadding="2">
  <tr bgcolor="#eeeeff">
    <td>Interest</td>
    <td><?=$interest;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Name</td>
    <td><?=$name;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Email</td>
    <td><?=$email;?></td>
  </tr>
  <tr bgcolor="#eeeeff">
    <td>Phone</td>
    <td><?=$phone;?></td>
  </tr>
  <tr bgcolor="#eeffee">
    <td>Message</td>
    <td><?=$message;?></td>
  </tr>
</table>
</body>
</html>
<?
$body = ob_get_contents();

$to = 'mark.bauer@med.fsu.edu';
$email = 'email@example.com';
$fromaddress = "you@example.com";
$fromname = "Online Contact";

require("phpmailer.php");

$mail = new PHPMailer();

$mail->From     = "mark.bauer@med.fsu.edu";
$mail->FromName = "Mark Bauer";
$mail->AddAddress("mark.bauer@med.fsu.edu","Med"); // Put your email

$mail->WordWrap = 50;
$mail->IsHTML(true);

$mail->Subject  =  "Contact form submitted";
$mail->Body     =  $body;
$mail->AltBody  =  "This is the text-only body";

if(!$mail->Send()) {
    $recipient = 'mark.bauer@med.fsu.edu';
    $subject = 'Contact form failed';
    $content = $body;   
  mail($recipient, $subject, $content, "From: mail@yourdomain.com\r\nReply-To: $email\r\nX-Mailer: DT_formmail");
  exit;
}
?>

【问题讨论】:

  • 使用的是什么方法?看起来表单正在使用 POST 但这可能会使用 javascript 进行修改。
  • 是的,我相信它正在使用 POST
  • 你在 process.php 上得到了那个。那它在哪里?
  • action="/contact.html" 替换为action="",使页面重新执行。

标签: php contact-form


【解决方案1】:

POST 方法经常会出现 405 错误。您可能试图在网站上引入某种输入表单,但并非所有 ISP 都允许处理表单所需的 POST 方法。

所有 405 错误都可以追溯到 Web 服务器的配置和管理网站内容访问的安全性,因此您的 ISP 应该很容易解释。

【讨论】:

  • 好的,我会调查的。谢谢