doucheng1063 2017-11-05 12:40 采纳率: 100%
浏览 91
已采纳

我们对用户进行身份验证的方式不再有效,从而导致身份验证错

I have this PHP function:

public static function smtpmailer($to, $from, $from_name, $subject, $body) { 
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 
    $mail->Username = "someemail@gmail.com";  
    $mail->Password = "somepassword";           
    $mail->SetFrom($from, $from_name);
    $mail->Subject = $subject;
    $mail->Body = $body;
    if (is_string($to)) {
        $to = array($to);
    }
    foreach ($to as $t) {
        $mail->AddAddress($t);
    }
    if(!$mail->Send()) {
        $error = 'Mail error: '.$mail->ErrorInfo; 
        return false;
    } else {
        $error = 'Message sent!';
        return true;
    }
}

This was successfully used before, but now it gives me an error I do not understand:

string(1553) "Warning [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

Some authentication does not pass, but both the username and password is correct. This was used from URL1 successfully before and I copied this code to another site, having URL2. However, the error mentioned above occurred. When I tried this at URL1, to find out whether this is a settings problem in my gmail account used for email verification, I encountered the same error. My question is: what should I fix and how in order to be able to successfully send an authentication email in terms of settings of the gmail account and the code I've shown above?

EDIT

Differences between this question and the one marked as the on this being duplicate with:

  • this is a question involving PHP code, that question is about Pythonic problems
  • this question is very specific about gmail usage and the desire of comply to google smtp terms and policies
  • the other question is about file downloading, this one is about sending an email from a given gmail address
  • the other question is about a popup with certificates in the browser, things here happen on server-side
  • 写回答

1条回答 默认 最新

  • dqrfdl5708 2017-11-05 16:00
    关注

    The steps for the solution were as follows:

    1. Make sure that the gmail account allows access from the app. You can do this by going to the settings of the account and Let Less Secure apps use your account,

    2. Make sure that PHPMailer corresponds to the PHP version in use

    3. We need the following settings:

    $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail $mail->Host = 'smtp.gmail.com'; $mail->Port = 587;

    1. Also, make sure we set the SMTPOptions:

      $mail->SMTPOptions = array(
      'ssl' => array(
              'verify_peer' => false,
              'verify_peer_name' => false,
              'allow_self_signed' => true
          )
      );
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解