zoukankan      html  css  js  c++  java
  • thinkphp5.1在php7.3下使用phpmailer报错

    thinkphp5.1在php7.3下使用phpmailer报错:

    unable to select [11]: Resource temporarily unavailable (max_fd=592)

    1、邮箱开启授权,获取授权码

    首先在163邮箱中开启smtp授权(imap和pop两个我都开了)

    2、安装phpmailer

    composer require phpmailer/phpmailer

    在common.php中写一个公共方法:

    <?php
    // +----------------------------------------------------------------------
    // | ThinkPHP [ WE CAN DO IT JUST THINK ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
    // +----------------------------------------------------------------------
    // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
    // +----------------------------------------------------------------------
    // | Author: 流年 <liu21st@gmail.com>
    // +----------------------------------------------------------------------
    
    // 应用公共文件
    
    // 发送邮件
    use PHPMailerPHPMailerPHPMailer;
    use PHPMailerPHPMailerException;
    
    function mailto($to, $title, $content)
    {
        $mail = new PHPMailer(true);
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );
    
        try {
            //Server settings
            $mail->SMTPDebug = 0;                      // Enable verbose debug output
            $mail->CharSet = 'utf-8';
            $mail->isSMTP();                                            // Send using SMTP
            $mail->Host       = 'smtp.163.com';                    // Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
            $mail->Username   = 'chenyingying1016@163.com';                     // SMTP username
            $mail->Password   = '这里填写授权码';                               // SMTP password
            $mail->SMTPSecure = 'ssl';         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
            $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
    
            //Recipients
            $mail->setFrom('chenyingying1016@163.com', 'cyy');
            $mail->addAddress($to);     // Add a recipient
    
            // Content
            $mail->isHTML(true);                                  // Set email format to HTML
            $mail->Subject = $title;
            $mail->Body    = $content;
    
            return $mail->send();
        } catch (Exception $e) {
              exception($mail->ErrorInfo, 1001);
        }
    }

    里要注意$mail->SMTPOptions 这个属性。如果是php5 不会影响这个发送结果。 如果是php7 不添加这个属性。会提示连接smtp 失败!!!!!!!!!

    3、发送短信

    mailto($data['email'], '注册管理员成功!', '注册管理员成功!');

    成功收取到短信

  • 相关阅读:
    迅为i.MX8M开发板Linux安卓9.0系统,四核CortexA53,单核CortexM4
    迅为龙芯2K1000开发板虚拟机ubuntu安装SSH服务
    迅为i.MX8MM开发板虚拟机Vmware的安装
    迅为龙芯2K1000开发板虚拟机ubuntu安装vscode
    归并排序XCoderLiu
    关于API中窗口子类化及超类化整理
    STL中最流行类模板vector
    andbook
    Navigation Failed: Cannot Find Application\HTML\1033\default.htm 错误解决办法
    html 播放音乐
  • 原文地址:https://www.cnblogs.com/chenyingying0/p/13234858.html
Copyright © 2011-2022 走看看