2017-06-16 4 views
0

私はこれまで何年も作業してきましたが、問題を見つけることができません。誰かがとても親切で私を助けてくれることを願っています。機能付きのhtmlメールを送信する

私は自分のメールスクリプト用の関数を作成しました。私は、フォームを持っている

<?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; 
    } 
    } 
} 

?> 

useful_functions.inc.php内の関数は、test.phpです。私は、私は、単純なHTMLフォームで正確なメーラーをテストし、同じようにそれを呼び出し、それが動作しましたHTTPエラー500

を得続けるtest.phpを実行すると、私は

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

でそれらをtest.phpを開始します。 マイ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

関連する問題