Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SMTP PHPMailer不';行不通_Php_Smtp - Fatal编程技术网

SMTP PHPMailer不';行不通

SMTP PHPMailer不';行不通,php,smtp,Php,Smtp,我尝试使用谷歌作为SMTP服务器,但它无法发送邮件。如何修复它?似乎有防火墙阻止了我的脚本 <?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

我尝试使用谷歌作为SMTP服务器,但它无法发送邮件。如何修复它?似乎有防火墙阻止了我的脚本

<?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.';
    }
尝试使用:

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

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