2017-06-16 72 views
0

我一直在這個問題上工作了很多年,只是找不到問題。希望有人能夠幫助我。發送功能的HTML郵件

我爲我的郵件腳本做了一個函數。該功能在裏面useful_functions.inc.php

<?php 
include ('mailer/class.phpmailer.php'); 

function sendmail($mail) 
{ 
    $mail = new PHPMailer(true); 

    if (($_SERVER["REQUEST_METHOD"] == "POST") && $geslachtErr== "" && $voornaamErr== "" && $familienaamErr== "" && $emailErr== "" && $telErr== "" && $afileErr== "") 
    { 
    $full_name = "Sofie Doe"; 
    $email  = "[email protected]"; 
    $subject = "HTML test mail."; 
    $text_message = "Hello ".$full_name.",<br /><br /> This is a test email in html.";   

    $message = "<html><body>"; 

    $message .= "<table width='100%' bgcolor='#e0e0e0' cellpadding='0' cellspacing='0' border='0'>"; 

    $message .= "<tr><td>"; 

    $message .= "<table align='center' width='100%' border='0' cellpadding='0' cellspacing='0' style='max-width:650px; background-color:#fff; font-family:Verdana, Geneva, sans-serif;'>"; 

    $message .= "<thead> 
      <tr height='80'> 
      <th colspan='4' style='background-color:#f5f5f5; border-bottom:solid 1px #bdbdbd; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:34px;' >TEST</th> 
      </tr> 
      </thead>"; 


    $message .= "</table>"; 

    $message .= "</td></tr>"; 
    $message .= "</table>"; 

    $message .= "</body></html>"; 

    try 
    { 
     $mail->IsSMTP(); 
     $mail->isHTML(true); 
     $mail->SMTPDebug = 0;      
     $mail->SMTPAuth = true;     
     $mail->SMTPSecure = "STARTTLS";     
     $mail->Host  = "mailout.one.com";  
     $mail->Port  = 587;    
     $mail->AddAddress($email); 
     $mail->Username ="[email protected]"; 
     $mail->Password ="Password";    
     $mail->SetFrom("[email protected]"); 
     $mail->AddReplyTo("[email protected]"); 
     $mail->Subject = $subject; 
     $mail->Body  = $message; 
     $mail->AltBody = $message; 
    } 
    } 
} 

?> 

我有一個表格,test.php。我開始他們的test.php與

<?php 
include ('useful_functions.inc.php') 
sendmail($mail); 
?> 

當我運行test.php我不斷收到HTTP錯誤500

我測試過用一個簡單的HTML表單的確切郵件,把它以同樣的方式和它的作品。 我test.php的作品,當我刪除sendmail($mail)並刪除我的useful_function.inc.php

這是爲什麼不工作的功能?

+2

一個500服務器錯誤;檢查日誌和/或啓用錯誤報告 –

+2

您的'try'語句缺少一個catch()塊。這是一個語法錯誤。一個好的IDE會向你發出警告。 – Barmar

+0

@ Fred-ii-啓用錯誤報告很少有助於解決500個錯誤。如果出現語法錯誤,則不會執行'error_reporting()'調用。 – Barmar

回答

1

爲什麼不通過修改try{}將電子郵件「自己發送」包括$mail->Send();

你的 「試一試」 將變爲:

try 
{ 
    $mail->IsSMTP(); 
    $mail->isHTML(true); 
    $mail->SMTPDebug = 0;      
    $mail->SMTPAuth = true;     
    $mail->SMTPSecure = "STARTTLS";     
    $mail->Host  = "mailout.one.com";  
    $mail->Port  = 587;    
    $mail->AddAddress($email); 
    $mail->Username ="[email protected]"; 
    $mail->Password ="Password";    
    $mail->SetFrom("[email protected]"); 
    $mail->AddReplyTo("[email protected]"); 
    $mail->Subject = $subject; 
    $mail->Body  = $message; 
    $mail->AltBody = $message; 
    $mail->Send(); 
    echo "Message Sent OK\n"; 
    } catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
    } catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
    } 
+0

它的工作原理!最後。謝謝! – WouterS