简体   繁体   English

SMTP PHPMailer不起作用

[英]SMTP PHPMailer doesn't work

I tried to use google as SMTP server like this but it cannot send mail. 我试图像这样使用谷歌作为SMTP服务器,但它无法发送邮件。 How to fix it? 怎么解决? It seems that there is firewall which blocks my script. 似乎有阻止我的脚本的防火墙。

<?php
    require("PHPMailer_5.2.4/class.phpmailer.php");

    $mail = new PHPMailer();
    $mail->SMTPDebug = true;
    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "smtp.gmail.com"; // SMTP server
    $mail->Port       = 465; // SMTP Port
    $mail->Username   = "emerald.hieu.test@gmail.com"; // SMTP account username
    $mail->Password   = "xxx";        // SMTP account password

    $mail->SetFrom('emerald.hieu.test@gmail.com', 'Hieutot'); // FROM
    $mail->AddReplyTo('emerald.hieu.test@gmail.com', 'Hieutot'); // Reply TO

    $mail->AddAddress('nguyen.hieu@xxx.vn', 'HieuND2'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";

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

This is my log: 这是我的日志:

SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "" 
SMTP -> get_lines(): $data is "" 
SMTP -> get_lines(): timed-out (10 seconds) 
SMTP -> FROM SERVER: 
SMTP -> get_lines(): $data was "" 
SMTP -> get_lines(): $str is "" 
SMTP -> get_lines(): $data is "" 
SMTP -> FROM SERVER: 
SMTP -> ERROR: EHLO not accepted from server: 
SMTP -> FROM SERVER: 
SMTP -> ERROR: HELO not accepted from server: 
SMTP -> ERROR: AUTH not accepted from server: 
SMTP -> NOTICE: EOF caught while checking if connectedThe following From address failed: emerald.hieu.test@gmail.com : Called Mail() without being connected Message was not sent.Mailer error: The following From address failed: emerald.hieu.test@gmail.com : Called Mail() without being connected

try using: 尝试使用:

$mail->Host = "ssl://smtp.gmail.com";

in place of: 取代:

$mail->Host = "smtp.gmail.com";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM