php-mail()不断返回false.编码问题或主机问题


php mail() keeps returning false. Coding issue or hosting issue

我有以下.php文件:

<?php
$to = "myaddress@gmail.com";
$from = $_POST["from"];
$subject = $_POST["subj"];
$message = $_POST["body"];
$headers = "From: ".$from.
     " X-Mailer: php";
if(mail($to, $subject, $message, $headers)){
  header("Location: resume.html");
} else{
   echo("<p>".$to." ".$from." ".$subject." ".$message." ".$headers."</p>");
}
?>

每次调用它时,它都返回false。有什么想法吗?

您的标题格式不正确。它们之间必须有'r'n,而不是像这里那样有空格。

$headers = "From: ".$from."'r'n"
          ."X-Mailer: php";