2012-07-16 37 views
3

當我嘗試使用的PHPMailer類我得到這個錯誤發送電子郵件: 梅勒錯誤:郵件正文爲空:PHP梅勒類問題:郵件正文空

<?php 

    include("class.phpmailer.php"); 

    $mail = new PHPMailer(); 
    $mail->IsSMTP(); 

    $mail->SMTPAuth = true; 

    $mail->SMTPSecure = "ssl"; 
    $mail->Host  = "rsb20.rhostbh.com"; 
    $mail->Port  = 465; 
    $mail->Username = "jobserreker+furrtexlab.com"; 
    $mail->Password = "12345678a"; 

    $mail->From  = "[email protected]"; 
    $mail->FromName = "Job Seeker"; 
    $mail->Subject = $_GET['subject']; 
    $mail->MsgHTML($_GET['msg']); 

    $mail->AddAddress($_GET['to'],"name to"); 
    $mail->IsHTML(false); 

    if(!$mail->Send()) 
    { 
     echo "Mailer Error: " . $mail->ErrorInfo; 

    }else{ 

     echo "Message sent!"; 
    } 
?> 
+0

任何機會$ _GET ['msg']爲空? – unfrev 2012-07-16 14:45:29

+1

如果您使用$ mail-> MsgHTML($ _ GET ['msg']);但接着說$ mail-> IsHTML(false);你是不是應該使用其他屬性來設置文本?像Body這樣的屬性?或者也許$ _GET ['msg']是空的? – 2012-07-16 14:46:20

+0

你可以請'回聲'--->'。 $ _GET ['msg']。 '<---',爲了檢查'$ _GET ['msg']'的內容? – fsenart 2012-07-16 14:47:51

回答

5

正如傑拉德Versluis說,因爲你設置IsHTML()爲false,則必須使用 - > Body屬性來設置郵件的實際正文。

$mail->Body = $_GET['msg']; 

您還應該使用POST而不是GET來提交導致執行操作的內容。

+0

這也行不通。一些消息被髮送,其中一些獲得該響應 – Aan 2012-07-16 15:27:19

+1

當您收到消息並在問題中發佈結果時,添加一個var_dump($ mail)。檢查barf的消息只是執行一個if(empty($ this-> Body)),所以我猜你沒有把它設置爲你認爲你設置的值(或者調用其他的重置 - >體)。 – MatsLindh 2012-07-16 16:22:21

0

我有這兩行代碼,但沒有任何contents.html文件,我不得不創建一個以避免錯誤。

//Read an HTML message body from an external file, convert referenced imagesto embedded, 
//convert HTML into a basic plain-text alternative body 
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 

//Replace the plain text body with one created manually 
$mail->AltBody = 'This is a plain-text message body';`