PHP邮件功能不发送。需要另一套眼睛

时间:2012-08-16 19:37:01

标签: php email if-statement

<?php
    session_start();

    $returnURL = $_POST["pageURL"].'#confirmation';

    if (empty($_POST["phone"]) || empty($_POST["email"]) || empty($_POST["name"])  || empty($_POST["address"]) ) {

    $_SESSION["confirmation"] = "empty";
    header('Location: '.$returnURL);
    exit;

    } else {

    $to = 'email@email.com';
    $headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . '>';
    $subject = 'Email from your landing page';          
    $message = (
    "You have received a inquiry from your landing page! \n\n Name: " . $_POST["name"] . " 
    \n Email: " . $_POST["email"] . "
    \n Phone Number: " . $_POST["phone"] .  "
    \n Mailing Address: " . $_POST["address"] .  "
    \n Message: " . $_POST["message"]
    );

    mail($to, $subject, $message, $headers);

    $_SESSION["confirmation"] = 'yes';
    header('Location: '.$returnURL);
    exit;
    }
?>

2 个答案:

答案 0 :(得分:0)

请参阅mail函数的文档,它会返回一个值。检查并报告回来。调试时也禁用重定向:

$result = mail($to, $subject, $message, $headers);
var_dump($result);
exit;

答案 1 :(得分:0)

标题可能非常挑剔。尝试在From。

的末尾添加新行
$headers = 'From: ' . $_POST["name"] . '<' . $_POST["email"] . ">\r\n";