PHP电子邮件未发送

时间:2015-02-12 20:31:50

标签: php email phpmailer

我使用此代码发送电子邮件:

当我在浏览器中打开mail.php文件时。什么都不会发送。浏览器将加载一个空白页面,但不显示消息,说明已发送电子邮件。我一直在StackOverflow和其他网站上搜索解决方案。有人能帮助我吗?

<?php

require_once("phpmailer\class.phpmailer.php"); 
// path to the PHPMailer class.

require_once("phpmailer\PHPMailerAutoload.php");


$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";


$mail->Port = "25"; 
// 8025, 587 and 25 can also be used. Use Port 465 for SSL.

$mail->SMTPAuth = true;
//$mail->SMTPSecure = 'ssl'; 
// Uncomment this line if you want to use SSL.

$mail->Username = "emailer@my.domain";
$mail->Password = "password";

$mail->From     = "example@gmail.com";
$mail->FromName = "Susan Sender";
$mail->AddAddress("rachel@my.domain", "Rachel Recipient");
//$mail->AddReplyTo("Your Reply-to Address", "Sender's Name");

$mail->Subject  = "Hi!";
$mail->Body     = "Hi! How are you?";
$mail->WordWrap = 50;  

if(!$mail->Send()) 
{
    echo 'Message was not sent.';
    echo 'Mailer error: ' . $mail->ErrorInfo;
    exit;
} 
else {
        echo 'Message has been sent.';
}
 ?>

0 个答案:

没有答案