【问题标题】:PHP form contact, with checkboxs, error 500PHP表单联系人,带有复选框,错误500
【发布时间】:2016-09-26 18:37:44
【问题描述】:

谁能帮帮我!这个 php 在我的网站上不起作用,不发送电子邮件,如果我更改 die(错误),页面对我说..

有de php动作

    <?php
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['mail'];
$Title = $_POST ['position/title'];
$company = $_POST ['company'];
$location = $_POST ['location'];
$telephone = $_POST['telephone'];
$services = $_POST['services'];
$string = join(" \r\n ", $services);
$timeframe = $_POST['timeframe'];
$comments = $_POST['comments'];
$learn = $_POST['learn'];
        $message = '<html><body>';
        $message .= '<img src="http://www.corbisglobal.com/assets/web/img/contact-CG-logo.png" />';
        $message .= '<table rules="all" style="border-color: #666; border : 1px;" cellpadding="10">';
        $message .= "<tr style='background: #ddd;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['name']) .  "</td></tr>";
         $message .= "<tr style='background: #eee;'><td><strong>Lastname:</strong> </td><td>" . strip_tags($_POST['lastname']) . "</td></tr>";
        $message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['mail']) . "</td></tr>";
         $message .= "<tr><td><strong>Title/Position:</strong> </td><td>" . strip_tags($_POST['position/title']) . "</td></tr>";
        $message .= "<tr><td><strong>Company:</strong> </td><td>" . strip_tags($_POST['company']) . "</td></tr>";
        $message .= "<tr><td><strong>Location:</strong> </td><td>" . strip_tags($_POST['location']) . "</td></tr>";
         $message .= "<tr><td><strong>Services:</strong> </td><td>" . join(" \r\n, ", $services) . "</td></tr>";
         $message .= "<tr><td><strong>Timeframe:</strong> </td><td>" . strip_tags($_POST['timeframe']) . "</td></tr>";
         $message .= "<tr><td><strong>Learn about Corbis:</strong> </td><td>" . strip_tags($_POST['learn']) . "</td></tr>";
        $message .= "<tr><td><strong>Comments:</strong> </td><td>" . strip_tags($_POST['comments']) . "</td></tr>";
        $message .= "</table>";
        $message .= "</body></html>";
$recipient = "recipient@example.com";
$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";
$mailheader .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($recipient, $subject, $message, $mailheader) or die (error);
header("Location: thankyou.php"); 
exit; 
?>

【问题讨论】:

  • A 500 错误 = 服务器错误(可能是一些 PHP 错误)。检查您的错误日志或打开显示错误,您将收到可以与我们分享的正确错误消息。在这里你可以看到如何打开它:stackoverflow.com/questions/1053424/…
  • 顺便说一句,你为什么将所有的post值都存储在变量中,然后直接使用post变量,以后呢?

标签: php forms checkbox contact-form


【解决方案1】:

您的错误可能在中间一行:

$subject = "Contact Form from CorbisGlobal Web";
$mailheader .= "MIME-Version: 1.0\r\n";
$mailheader .= "From: " . strip_tags($_POST['mail']) . "\r\n";

在向变量添加更多文本之前,您没有创建变量 $mailheader

打开错误报告,您将获得有意义的错误消息,帮助您解决大部分问题。

另外,你正在这样做:

mail($recipient, $subject, $message, $mailheader) or die (error);

or die (error),您可能没有定义error 常量,并且在您向我们展示的代码中没有具有此名称的变量。要检查mail 函数是否接受了您的输入,您可以这样做:

if (mail($recipient, $subject, $message, $mailheader)){
    header("Location: thankyou.php"); 
}
else{
    die("Error sending email");
}

【讨论】:

  • 是的,大概就是这样(假设 OP 没有省略这个)
  • 我严重怀疑这会导致 http 500 错误。
  • 他的“or die”功能也有问题,我已经添加到答案中了。
  • 开启错误时,出现:Warning: join(): Invalid arguments pass in /srv/www/corbis-www/mail.php on line 12 Warning: join(): Invalid arguments在第 30 行传入 /srv/www/corbis-www/mail.php 发送电子邮件时出错当我删除此行时..死..发送电子邮件时出错...
  • 我的意思是,你发送$services 作为你join()-call 中的第二个参数。如果这不是一个数组,您将收到刚刚显示的错误。 join()implode() 的别名。这是它的手册:php.net/manual/en/function.implode.php
猜你喜欢
  • 2012-06-25
  • 2012-09-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-26
  • 2015-05-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多