2014-02-07 132 views
0

PHPMailer说成功,但没有发送电子邮件。电子邮件跟踪不显示任何错误。从发送或接收电子邮件。有什么我失踪了吗?phpmailer成功,但没有发送电子邮件

下面是我的mailer.php文件:

require 'class.phpmailer.php'; 
require 'class.smtp.php'; 

$mail = new PHPMailer; 


$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'localhost'; // Specify main and backup server 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';       // SMTP username: FROM EMAIL 
$mail->Password = 'pw';       // SMTP password: FROM PW 


$mail->From = '[email protected]'; //FROM EMAIL 
$mail->addAddress('[email protected]');    // Add a recipient, Name is optional 


$mail->WordWrap = 50;         // Set word wrap to 50 characters 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Contact Form'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
    exit; 
} 

echo 'Message has been sent'; 

回答

-3

我不知道你为什么用这种方法在PHP中发送电子邮件。这里有一个更好的方式来做到这一点:

$to = '[email protected]'; 
$subject = 'Lorem Ipsum'; 
$from = '[email protected]'; 
$message = 'Congrats! You won! Message body here.'; 
$headers = "From:" . $from; 
mail($to,$subject,$message,$headers); 
+2

显然,这个人必须能够使用SMTP认证用于发送电子邮件,所以你的基本的解决方案肯定是不会去帮助他们。 –