• mantis 使用 465端口后,无法发送邮件


    mantis使用PHPMailer编写发送邮箱的代码

    PHPMailer需PHP的socket扩展支持,而PHPMailer链接qq域名邮箱时需要ssl加密方式,固php还得openssl的支持,可以查看phpinfo,如下两项均存在则可以使用
    以下得php脚本可以测试mail得错误原因,我这边的报错是

    2018-12-26 05:37:50     Connection: opening to ssl://smtp.123.com:465, timeout=300, options=array ( )
    2018-12-26 05:37:50     Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
                                              error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [/usr/local/httpd-2.4.27/htdocs/mantisbt/vendor/phpmailer/phpmailer/class.smtp.php line 294]
    2018-12-26 05:37:50     Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [/usr/local/httpd-2.4.27/htdocs/mantisbt/vendor/phpmailer/phpmailer/class.smtp.php line 294]
    2018-12-26 05:37:50     Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.123.com:465 (Unknown error) [/usr/local/httpd-2.4.27/htdocs/mantisbt/vendor/phpmailer/phpmailer/class.smtp.php line 294]
    2018-12-26 05:37:50     SMTP ERROR: Failed to connect to server:  (0)
    

    加上了忽略证书错误后,可以正常发送

    <?php
    
    header("Content-Type:text/html;charset=utf-8");
    
    
    require 'PHPMailerAutoload.php'; // 脚本要跟PHPMailerAutolad.php放在同一目录
    
    // debug 等级
    $mail = new PHPMailer;
    
    //   -----------------
    //   这个配置应该是不验证证书
    
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );
    
    // --------------------
    
    $mail->SMTPDebug = 3;                               // Enable verbose debug output
    
    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.123.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = '123@123.com';                 // SMTP username
    $mail->Password = '123';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to
    
    
    
    
    $mail->setFrom('123@123.com', 'Mailer');
    $mail->addAddress('123@123.com', 'Joe User');     // Add a recipient
    $mail->addReplyTo('123@123.com', 'Information');
    $mail->addCC('123@123.com');
    
    $mail->addAttachment('/etc/fstab', 'fstab');    // Optional name
    $mail->isHTML(true);                                  // Set email format to HTML
    
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    
    ?>
    
    在mantis得core/email_api.php中
    $t_mail->IsHTML( false );              # set email format to plain text  
    得上面加上
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );
    后正常发送邮件
    
  • 相关阅读:
    编译使用tinyxml
    GitLab 项目创建后地址由Localhost改为实际IP的方法
    树莓派相机设定
    MongoDB的数据备份与恢复
    Nginx PHP fpm forbidden 原因
    PSR2规范
    docker 日志管理
    Docker 拷贝文件
    Docker MySQL基本操作
    deepin安装php5.6
  • 原文地址:https://www.cnblogs.com/blackmood/p/10178808.html
Copyright © 2020-2023  润新知