加载时发生500错误"发送电子邮件"页

时间:2013-04-18 14:37:26

标签: php html-email

Sp我正在尝试发送电子邮件,代码工作正常,直到我从标准电子邮件切换到html电子邮件。

现场直播:http://kenthomes.net/Amelia-Cove

点击“分享此计划”。

我的代码是:

    $person = $_POST["name"];

    //Where will you be pulling emails from?
    $emailDB = "emailAddresses";
    $type = $_POST["type"];

    //Get Share URL that is misformatted.
    $waybefore = $_GET["share"];
    $before = str_replace("*", "?", $waybefore);
    $shareMe = str_replace("!", "=", $before);

    $id = $_SERVER['HTTP_REFERER']; 
    $id = $_SERVER['HTTP_REFERER']; 
    //Where do you want a copy of this email to go to? (or null)
    $copyDB = "";

    if($_GET["com"])
    {
        $prettyType = "Community";
    }
    else if($_GET["inv"])
    {
        $prettyType = "Move-In Ready Home";
    }
    else if($_GET["mod"])
    {
        $prettyType = "Model Home";
    }

    $_POST["date"] = date("Y-m-d");

    $Emails = new Controller($emailDB, null, null, true);

    $ed = $Emails->getData();

    //
    // The good stuff
    //

    $emailTo = $_POST["email"];
    $subject = "Kent Homes - " . $person . " would like to share a " . ucwords(strtolower($_GET['type'])) . " with you!";

    $out = '<html><body>';
    $out .= $person . " thought you would like this " . $prettyType . " by Kent Homes.  Click the link to view: http://kenthomes.net" . $shareMe . "</br></br>";
    $out .= "Additional Message from " . $person . "</br>";
    $out .= $_POST['msg'];
    $out .= '</body></html>';

    $headers = "From: " . $person "<noreply@kenthomes.com>\r\n";
    $headers .= "Reply-To: <noreply@kenthomes.com\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion()."\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    //
    // Send 'er off!
    //

    mail($emailTo, $subject, $out, $headers);

    if($toEmail) {
        mail($emailTo, $subject, $out, $headers);
    }

    echo "<p>This " . ucwords(strtolower($_GET['type'])) . " has been sent to " . $_POST["email"] . ".</p>";
    unset($_POST["id"]);

我收到错误:

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

这就是html邮件之前功能代码的样子:

            $Captcha = new MCaptcha();
                if($_POST["submitit"])
                {
                    $answer = $Captcha->checkAnswer();
                    if($answer)
                    {
                        $person = $_POST["name"];
                        $emailTo = $_POST["email"];
                        $subject = "Kent Homes - " . $person . " would like to share a " . ucwords(strtolower($_GET['type'])) . " with you!";

                        //Where will you be pulling emails from?
                        $emailDB = "emailAddresses";
                        $type = $_POST["type"];

                        //Get Share URL that is misformatted.
                        $waybefore = $_GET["share"];
                        $before = str_replace("*", "?", $waybefore);
                        $shareMe = str_replace("!", "=", $before);

                        $id = $_SERVER['HTTP_REFERER']; 
                        $id = $_SERVER['HTTP_REFERER']; 
                        //Where do you want a copy of this email to go to? (or null)
                        $copyDB = "";

                        if($_GET["com"])
                        {
                            $prettyType = "Community";
                        }
                        else if($_GET["inv"])
                        {
                            $prettyType = "Move-In Ready Home";
                        }
                        else if($_GET["mod"])
                        {
                            $prettyType = "Model Home";
                        }

                        $out = $person . " thought you would like this " . $prettyType . " by Kent Homes.  Click the link to view: http://kenthomes.net" . $shareMe . " ";

                        $_POST["date"] = date("Y-m-d");

                        $Emails = new Controller($emailDB, null, null, true);

                        $ed = $Emails->getData();

                        mail($emailTo, $subject, $out, $headers);

                        if($toEmail) {
                            mail($emailTo, $subject, $out, $headers);
                        }

                        echo "<p>This " . ucwords(strtolower($_GET['type'])) . " has been sent to " . $_POST["email"] . ".</p>";
                        unset($_POST["id"]);
                    }
                }

2 个答案:

答案 0 :(得分:0)

我没有看到导致500的代码有任何问题。看不见的项目可能导致500:

  1. 是否包含并定义了“控制器”?
  2. 在构建导致500?
  3. 的Controller时是否会发生任何事情
  4. 您为了制作此代码段而删除的代码中是否存在语法错误?
  5. 首先,我会查看你的apache日志。在Ubuntu中,它们通常位于/var/log/apache2/error.log中。如果您的错误日志中没有打印任何内容,那么您可能会耗尽内存或时间。我怀疑是这种情况,但如果确实如此,那么这些将有所帮助:

    ini_set('memory_limit','1G'); 参数或者set_time_limit(3600);

    它们将帮助您进行诊断,但您希望根据用例配置运行时。

    如果您的错误日志中打印了某些内容,请对其进行调查 - 这可能就是问题所在。

    如果这些都没有帮助,请尝试在脚本中间死亡,看看它到底有多远。一旦你找到了令人讨厌的代码,它就会自行消亡,而不会打印出消息。

    死(“到了这里”);

答案 1 :(得分:0)

语法错误:

$out .= "Additional Message from " $person . "</br>";

这应该是:

$out .= "Additional Message from " . $person . "</br>";