未捕获的异常' PHPMailer \ PHPMailer \ Exception'无法连接SMTP证书错误

时间:2018-02-05 18:40:54

标签: ssl smtp phpmailer

我正在尝试使用gmail smtp服务器和phpmailer从我的localhost发送电子邮件。  当我提交表单时,我收到了以下错误。

2018-02-05 18:36:19 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP e22sm5767718ioj.79 - gsmtp
2018-02-05 18:36:19 CLIENT -> SERVER: EHLO localhost
2018-02-05 18:36:19 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [142.237.177.21]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-02-05 18:36:19 CLIENT -> SERVER: STARTTLS
2018-02-05 18:36:19 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-02-05 18:36:19 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [C:\wamp64\www\test\phpmailer\src\SMTP.php line 405]
SMTP Error: Could not connect to SMTP host.
2018-02-05 18:36:19 CLIENT -> SERVER: QUIT
2018-02-05 18:36:19 
2018-02-05 18:36:19 
2018-02-05 18:36:19 Connection: closed
SMTP Error: Could not connect to SMTP host.

( ! ) Fatal error: Uncaught exception 'PHPMailer\PHPMailer\Exception' with message 'SMTP Error: Could not connect to SMTP host.' in C:\wamp64\www\test\phpmailer\src\PHPMailer.php on line 1898

我尝试了我能做的一切,但没有成功。

下面是我的代码。



<?php

require_once 'dbconfig.php';

class USER
{ 

 private $conn;
 
 public function __construct()
 {
  $database = new Database();
  $db = $database->dbConnection();
  $this->conn = $db;
    }
 
 public function runQuery($sql)
 {
  $stmt = $this->conn->prepare($sql);
  return $stmt;
 }
 
 public function lasdID()
 {
  $stmt = $this->conn->lastInsertId();
  return $stmt;
 }
 
 public function register($uname,$email,$upass,$code)
 {
  try
  {       
   $password = md5($upass);
   $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode) 
                                                VALUES(:user_name, :user_mail, :user_pass, :active_code)");
   $stmt->bindparam(":user_name",$uname);
   $stmt->bindparam(":user_mail",$email);
   $stmt->bindparam(":user_pass",$password);
   $stmt->bindparam(":active_code",$code);
   $stmt->execute(); 
   return $stmt;
  }
  catch(PDOException $ex)
  {
   echo $ex->getMessage();
  }
 }
 
 public function login($email,$upass)
 {
  try
  {
   $stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
   $stmt->execute(array(":email_id"=>$email));
   $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
   
   if($stmt->rowCount() == 1)
   {
    if($userRow['userStatus']=="Y")
    {
     if($userRow['userPass']==md5($upass))
     {
      $_SESSION['userSession'] = $userRow['userID'];
      return true;
     }
     else
     {
      header("Location: index.php?error");
      exit;
     }
    }
    else
    {
     header("Location: index.php?inactive");
     exit;
    } 
   }
   else
   {
    header("Location: index.php?error");
    exit;
   }  
  }
  catch(PDOException $ex)
  {
   echo $ex->getMessage();
  }
 }
 
 
 public function is_logged_in()
 {
  if(isset($_SESSION['userSession']))
  {
   return true;
  }
 }
 
 public function redirect($url)
 {
  header("Location: $url");
 }
 
 public function logout()
 {
  session_destroy();
  $_SESSION['userSession'] = false;
 }
 
 function send_mail($email,$message,$subject)
 {      
  	

	require 'C:\wamp64\www\test\phpmailer\src\Exception.php';
	require 'C:\wamp64\www\test\phpmailer\src\PHPMailer.php';
	require 'C:\wamp64\www\test\phpmailer\src\SMTP.php';
  $mail = new PHPMailer\PHPMailer\PHPMailer(true);
  $mail->IsSMTP();
  
  $mail->SMTPDebug = 3;
  $mail->SMTPAuth   = true;                  
  $mail->SMTPSecure = 'tls';                 
  $mail->Host       = 'smtp.gmail.com';      
  $mail->Port       = 587;
  $mail->Username= "solankij978@gmail.com";  
  $mail->Password= "9724929143";            
  $mail->SetFrom('solankij978@gmail.com','Sachin Patel');
  $mail->AddReplyTo('deeshanpatel@gmail.com','Sachin Patel');             
  $mail->AddAddress($email);
  $mail->Subject    = $subject;
  $mail->MsgHTML($message);
  $mail->Send();
 } 
}
&#13;
&#13;
&#13;

请帮帮我。

0 个答案:

没有答案