dongzuo9096 2017-05-24 10:44
浏览 34
已采纳

500内部服务器错误(联系表单,PHP)

We are running a website on a local server. After entering the required data into contact form and clicking the button Send, we get the "500 Internal Server Error". I'm assuming this relates to PHP mail configuration for local servers.

PHP:

<?php
if(isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["msg"])){
  $name = $_POST["name"];
  $email = $_POST["email"];
  $subject = $_POST["subject"];
  $msg = nl2br($_POST["msg"]);
  $to = "info@companyname.com";
  $from = $email;
  $message = "<b>Name:</b> ".$name." <br><b>E-mail:</b> ".$email." <br><b>Subject:</b> ".$subject." <br><p> ".$msg." </p>";
  $headers = "MIME-Version: 1.0" . "
";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "
";
  $headers .= "From: $from" . "
";
    if(mail($to, $subject, $message, $headers)){
        echo "Success";
    }else{
        echo "The server failed to send the message. Please try again later.";
    }
}
?>

JS:

function _(id){return document.getElementById(id);}
function submitForm(){
  _("submit").disabled = true;
  _("status").innerHTML = "Please wait...";

  var formdata = new FormData();
  formdata.append("name", _("name").value);
  formdata.append("email", _("email").value);
  formdata.append("subject", _("subject").value);
  formdata.append("msg", _("msg").value);

  var ajax = new XMLHttpRequest();
  ajax.open("POST", "contact.php");
  ajax.onreadystatechange = function(){
    if(ajax.readyState == 4 && ajax.status == 200){
      if(ajax.responseText == "Success"){
        _("status").innerHTML = "";
        _("response").innerHTML = "Your message has been successfully sent.";
      }else{
        _("status").innerHTML = ajax.responseText;
        _("submit").disabled = false;
      }
    }
  }
  ajax.send(formdata);
}
  • 写回答

2条回答 默认 最新

  • doudu9652 2017-06-02 06:16
    关注

    Solved. The problem was with the configuration of our local server which runs on MS IIS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用