【问题标题】:My php contact form is redirecting on an error 500我的 php 联系表单正在重定向错误 500
【发布时间】:2015-10-26 12:56:34
【问题描述】:

我几个小时前启动了我的网站,但我的联系表无法正常工作! 我遵循了很多教程,但没有一个对我有用,一定是某个地方有错误......

这是我的 HTML 表单,在我的主页 index.html 上可见:

<form action="mail.php" class="contact-form" method="POST">
<fieldset>

    <input name="obj" type="text"><br>
    <textarea name="message"></textarea>

    <input name="from-name" type="text"><br> 
    <input name="from-mail" type="text"><br> 

    <input type="submit" value="Send">

</fieldset></form>

这是我的 mail.php 文件的内容,位于我服务器上 index.html 的同一个文件夹中。 mail.php 仅包含以下代码,没有其他内容。

<?php $name = $_POST['from-name'];
$email = $_POST['from-mail'];
$obj = $_POST['obj'];
$message = $_POST['message'];

$formcontent="from: $name \n Message: $message";
$recipient = "XXX.XXX@gmail.com";
$subject = "$obj";
$mailheader = "from: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href="index.html"> Return Home</a>";
?>

所以在这里,每当我点击我的提交按钮时,Chrome 会立即将我重定向到服务器错误 500,没有发送消息。 我哪里做错了?

【问题讨论】:

  • &lt;a href="index.html"&gt;改成&lt;a href='index.html'&gt;!!
  • echo "Thank You!" . " -" . "&lt;a href='index.html'&gt; Return Home&lt;/a&gt;";替换echo "Thank You!" . " -" . "&lt;a href="index.html"&gt; Return Home&lt;/a&gt;";,你不能在另一个(")中使用(")。

标签: php html forms contact


【解决方案1】:

改一下

echo "Thank You!" . " -" . "<a href="index.html"> Return Home</a>";

到这里

echo "Thank You!" . " -" . "<a href='index.html'> Return Home</a>";

改进的代码

if (!mail($recipient, $subject, $formcontent, $mailheader)) {
    die("Error!");
}
else
{
    echo "Thank You!" . " -" . "<a href='index.html'>Return Home</a>";
}

【讨论】:

  • 完美运行!非常感谢!
  • @keyloags 乐于提供帮助 :)
【解决方案2】:

当您的 php 代码有致命错误但错误显示被关闭时,会发生“500 Internal Server Error”。你可以试试这个看看错误。

在你的 php 文件中:

ini_set('display_errors', 1);

在 .htaccess 文件中:

php_flag display_errors 1 

【讨论】:

    猜你喜欢
    • 2013-07-31
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-23
    • 1970-01-01
    相关资源
    最近更新 更多