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
    )
);
后正常发送邮件

转载于:https://www.cnblogs.com/blackmood/p/10178808.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值