PHP mail()后500错误

时间:2014-09-11 19:50:07

标签: php sendmail

UPDATE 我能够从我的客户端获得托管信息,我联系了支持人员,显然目前主机邮件功能存在问题,他们正在制定解决方案。将等待,看看是否是这个问题的原因,并将报告回来 END UPDATE

我正在尝试设置一个简单的联系表单,用于发送电子邮件。我将表单操作设置为以下PHP文件。

电子邮件已发送,但用户体验以500错误结束,而不是将用户发送到确认页面。

如果我注释掉mail()部分,那么表单会成功将用户重定向到确认页面,但当然不会发送任何电子邮件。

该网站托管在GoDaddy上,但我无法访问托管帐户,但如果需要,我可以尝试访问该网站。

这是PHP代码:

<?php

$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['CITY'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$howdidyouhear = $_POST['hear_about'];
$notifyshow = $_POST['notify_shows'];
$notifyonline = $_POST['notify_online'];
$interest_jewelry = $_POST['Interest_jewelry'];
$interest_prints = $_POST['interest_prints'];
$interest_folkart = $_POST['interest_folkart'];
$interest_indian = $_POST['interest_indian'];
$interest_closeouts = $_POST['interest_closeouts'];
$interest_other = $_POST['interest_other'];
$interest_other_text = $_POST['interest_other_text'];
$spamvalid = $_POST['validate'];
$honeypot = $_POST['website'];

//Spammer Handling
if ($honeypot!=null){echo 'You have been flagged as a spammer, please go away!'; exit;} 

if ($spamvalid != '357'){
    echo "
    <script>
        function goBack() {
            window.history.back()
        }
    </script>
    You didn't enter the correct number at the bottom of the form.  Please try again.<br><button onclick='goBack()'>Go Back</button>";
    exit;
}

//START EMAIL

//Body
$mailbody="Name: {$name}\n\nAddress: {$address}\n\nCity: {$city}\n\nState: {$state}\n\nZip: {$zip}\n\nEmail: {$email}\n\nHow did you hear about us?: {$howdidyouhear}\n\nWould you like to be notified when we will be doing a show in your area?: {$notifyshow}\n\nWould you like to receive email notifications of special sales and online events?: {$notifyonline}\n\nWhat brought you to mishuganah.com?: {$interest_jewelry} {$interest_prints} {$interest_folkart} {$interest_indian} {$interest_closeouts} {$interest_other}: {$interest_other_text}\n\n";

//Send Email
mail('matt.rodela@gmail.com','New submission from Mishuganah.com', $mailbody, "From:{$email}\r\n" );

header("Location: http://".$_SERVER["HTTP_HOST"]."/mailing_list/confirmation_page.htm");

?>

我是PHP的相对新手,所以请完整地解释您的解决方案。谢谢!

2 个答案:

答案 0 :(得分:0)

Use phpMailer instead of php mail() function below you will find reasons not to use built in php mail function

In some cases, mails send via PHP mail() did not receive the recipients although it was send by WB without any error message. The most common reasons for that issue are listed below.

    wrong format of mail header or content (e.g. differences in line break between Windows/Unix)
    sendmail not installed or configured on your server (php.ini)
    the mail provider of the recipeint does not allow mails send by PHP mail(); common spam protection

Errors in the format of header or content can cause that mails are treated as SPAM. In the best case, such mails are transfered to the spam folder of your recipient inbox or send back to the sender. In the worst case, such mails are deleted without any comment. If sendmail is not installed or not configured, no mails can be send at all.

It is common practice by free mail provider such as GMX, to reject mails send via the PHP function mail(). Very often such mails are deleted without any information of the recipient.

答案 1 :(得分:0)

所以事实证明这是GoDaddy结束时的一个问题,它已经解决了。表格现在正在运作。显然,代码没有任何问题。

感谢大家的建议,我学到了一些东西(现在要对我的输入进行整理和过滤)。