代码或服务器问题- PHP联系表单


Code or Server issue - PHP contact form?

我正在重新设计一个网站,并且刚刚将文件上传到主机,现在正在测试是否一切正常。消息表单不一致-有时它将用户发送到感谢确认页面,有时它显示错误:"500内部服务器错误,服务器遇到内部错误或配置错误,无法完成您的请求。"但是,没有测试电子邮件到达收件人地址,表明表单已经工作。奇怪的是,当我在mail .php文档中替换我的个人电子邮件地址时,它成功通过了。这让我觉得代码是有效的。

我怀疑这是一个服务器或电子邮件配置问题,因为我也有电子邮件的问题,改变主机后,但可能它与我的代码?

HTML:

<form class="form-horizontal" method="post" action="mailer.php" class="form-horizontal" role="form">
 <div class="form-group">
    <label for="name" class="col-sm-2"><small>Name</small></label>
    <div class="col-sm-10">
       <input type="text" class="form-control" id="inputName" name="inputName" placeholder="Enter your full name" required>
    </div>
</div>
<div class="form-group">
    <label for="email" class="col-sm-2"><small>Email</small></label>
    <div class="col-sm-10">
        <input type="email" class="form-control" id="inputEmail" name="inputEmail" placeholder="Enter your email, example@domain.com" required>
    </div>
</div>
<div class="form-group">
    <label for="name" class="col-sm-2"><small>Telephone</small></label>
        <div class="col-sm-10">
           <input type="text" class="form-control" id="inputPhone" name="inputPhone" placeholder="Enter your telephone number" required>
        </div>
</div>
<div class="form-group">
    <label for="message" class="col-sm-2"><small>Message</small></label>
    <div class="col-sm-10">
        <textarea class="form-control" rows="4" name="inputMessage" id="inputMessage" placeholder="Enter your message here" required></textarea>
    </div>
</div>
<div class="form-group">
<!-- The following field is for robots only, invisible to humans: -->
    <p class="robotic" id="pot">
        <label>If you're human leave this blank:</label>
            <input name="robotest" type="text" name="robotest" id="robotest" class="robotest" />
    </p>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
        <input style="font-size:22px;" id="submit" name="submit" type="submit" value="Send" class="btn">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
    <! Will be used to display an alert to the user>
</div>
</div>
</form>

mailer.php文件:

<?php
/* Set e-mail recipient */
$myemail = "info@domain.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['inputName'], "Your name was not entered correctly.");
$email = check_input($_POST['inputEmail'], "Your email address was not entered correctly.");
$phone = check_input($_POST['inputPhone'], "Your telephone number was not entered correctly.");
$message = check_input($_POST['inputMessage'], "Your message was not entered correctly.");
$robotest = $_POST['robotest'];
/* If e-mail is not valid show error message */
if (!preg_match("/(['w'-]+'@['w'-]+'.['w'-]+)/", $email))
{
show_error("Invalid e-mail address.");
}
/* ROBOT TEST */
if($robotest)
{
show_error("Denied, robot.");
}
/*  prepare the message for the e-mail */
$subject = "Inquiry from Website";
$message = "
Someone has sent you a message using your website's contact form:
Name: $name
Email: $email
Telephone: $phone
Subject: $subject
Message:
$message
";
/* send the message using mail() function */
mail($myemail, $subject, $message);
/* redirect visitor to the thank you page */
header('Location: http://www.website.com/thankyou.html');
exit();
/* functions used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again.</p>
</body>
</html>
<?php
exit();
}
?>

似乎您有服务器/配置问题。我已经使用了这个代码,并把它放在我自己的服务器上,它工作得非常好。(同样,干得漂亮,代码非常干净)

检查是否收到电子邮件时(特别是当个人邮件有效而公司邮件无效时)要考虑的一件事是电子邮件启发式。尝试更改内容设置和/或主题行。(我觉得主题行很可疑,我就从这里开始)。

https://en.wikipedia.org/wiki/Naive_Bayes_spam_filtering