简体   繁体   English

PHP mail()之后出现500错误

[英]500 error after PHP mail()

UPDATE I was able to get the hosting info from my client and I contacted support, apparently there's an issue with the hosts mail function at the moment and they are working on a resolution. 更新我能够从客户端获取托管信息,并且我与支持人员联系,显然主机邮件功能目前存在问题,他们正在努力解决问题。 Will wait to see if that's the cause of this problem and will report back. 请稍候,看是否是造成此问题的原因,并会报告。
END UPDATE 结束更新

I am trying to set up a simple contact form that will send an email. 我正在尝试建立一个简单的联系表单,该表单将发送电子邮件。 I have the form action set to the below PHP file. 我将表单操作设置为以下PHP文件。

The email gets sent, but the user experience ends with a 500 error instead of sending the user to the confirmation page. 电子邮件已发送,但是用户体验以500错误结束,而不是将用户发送到确认页面。

If I comment out the mail() part, then the form redirects the user to the confirmation page successfully, but of course no email gets sent. 如果我注释掉mail()部分,那么该表单会将用户成功重定向到确认页面,但是当然不会发送电子邮件。

The website is hosted on GoDaddy, and I don't have access to the hosting account, though I can try to get it if I need it. 该网站托管在GoDaddy上,尽管我可以在需要时尝试获取它,但我无权访问托管帐户。

Here's the PHP code: 这是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");

?>

I am a relative novice with PHP, so please explain your solutions fully. 我是PHP的相对新手,因此请充分说明您的解决方案。 Thanks! 谢谢!

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.

So it turns out it was an issue on GoDaddy's end and it has been resolved. 因此,事实证明这是GoDaddy的问题,已经解决。 The form is working now. 该表格现在可以使用。 Apparently there was nothing wrong with the code. 显然,代码没有错。

Thanks for the suggestions folks, I learned some stuff (going to sanatize and filter my inputs now). 感谢大家的建议,我学到了一些东西(现在要整理和过滤输入内容)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM