2013-04-18 267 views
0

Sp我試圖發送一封電子郵件,代碼工作正常,直到我從標準電子郵件切換到html電子郵件。加載「發送電子郵件」頁面時出現500錯誤

這是住在這裏: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 "<[email protected]>\r\n"; 
    $headers .= "Reply-To: <[email protected]\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"]); 
        } 
       } 
+0

那麼你的'error_log'說? '$ toEmail'設置爲你的'if($ toEmail){'check?看起來像兩次相同的「mail()」調用。 –

+0

是的,出於某種原因,當我刪除該聲明,如果聲明是奇怪的,我知道它沒有發送電子郵件。 –

+0

這可能是你問題的根源。 –

回答

0

我不看到會導致500的代碼的任何問題。看不見的項目,可能會導致500:

  1. 是否包含並定義了「控制器」?
  2. 在構建可能導致500的控制器時會發生什麼事嗎?
  3. 您爲刪除此代碼段而刪除的代碼中是否存在語法錯誤?

首先,我會檢查你的apache日誌。在Ubuntu中,它們通常位於/var/log/apache2/error.log中。如果沒有在您的錯誤日誌中打印,則可能是因爲內存或時間耗盡。我懷疑是這種情況,但如果是這樣,那麼這些將有所幫助:

ini_set('memory_limit','1G'); set_time_limit(3600);

他們將幫助您診斷,但您希望爲您的用例配置運行時。

如果在你的錯誤日誌中打印了某些東西,請調查它 - 這可能是問題所在。

如果沒有這些幫助,請嘗試在腳本中間死去,看看它有多遠。只要你碰到有問題的代碼片段,它就會自動死掉,而不會打印出死信息。 (「got here」);

die(「got here」);

+0

是的。我在代碼中的許多不同的地方放了一個die(),而不是骰子。我正在更新上面的代碼,以包含實際工作的代碼(在我去html之前) –

+0

你在apache日誌中有什麼錯誤? – mbarlocker

0

語法錯誤的:

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

這應該是:

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

很好的接收,同樣的問題,當設置'$頭' –

+0

嘿,是啊,這就是我的意思...不是出。 今天我的心在哪裏。 –