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 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器