2012-07-16 63 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';`