dongqie4402 2015-11-23 08:14
浏览 60

PHPMailer不会发送我的电子邮件也没有错误

I've been using the default mail function of PHP before but decided to use another service for emailing features. I used PHPMailer but it is not working.

    date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';


$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Host = gethostbyname('smtp.gmail.com');
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "xxx@gmail.com";
$mail->Password = "xxx";

$mail->setFrom('xxx@gmail.com', 'Name');

$mail->addReplyTo('xxx@gmail.com', 'no-reply');

$mail->addAddress('xxx@gmail.com', 'Name');
$mail->Subject = 'PHPMailer GMail SMTP test';

$mail->AltBody = 'This is a plain-text message body';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';

if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

The code also doesn't echo any errors.

  • 写回答

1条回答 默认 最新

  • douwei2713 2015-11-23 08:25
    关注

    It does not echo any errors, but I think it also doesn't echo 'Message sent!'

    Try the following

    Append the brackets

    $mail =  new PHPMailer();
    

    Set debug to messages AND ERRORS for testing purpose

    $mail->SMTPDebug = 1;
    

    To send HTML Body, either after setting $mail->Body call

    $mail->IsHTML(true);
    

    Or use the Method to set HTML body which will combine both of them:

    $mail->MsgHTML('This is the HTML message body <b>in bold!</b>');
    

    Try this and see if it works

    EDIT: Also look that the casing is as suggested (I am not sure if this may give errors, but just to be sure)

    $mail->SetFrom
    $mail->AddReplyTo
    $mail->AddAddress
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分