crypto php ssl,PHP 使用 PHPMailer 遇到 SSL operation failed 的解法

使用 PHP 寄信經常會使用 PHPMailer,但是要使用內部網路的 Mail

Server 來寄信,卻一直遇到如下述的錯誤:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1.

OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

要怎麼解決呢?

PHP 使用 PHPMailer 遇到 SSL operation failed 的解法

PHPMailer 常見的寫法如下:(註:設定 From、To、Subject、Body.. 在此就不寫了)

$mail = new PHPMailer(true);

$mail->isSMTP();

$mail->Host = 'relay-hosting.secureserver.net';

$mail->SMTPAuth = true;

$mail->Username = 'user@example.com';

$mail->SMTPSecure = 'tls';

?>

現在已經很習慣使用 SMTPSecure 為 tls 或 ssl,但是臨時自己架設的 Mail Server,沒有設定憑證、帳號、密碼,修改範例如下:

$mail = new PHPMailer(true);

$mail->SMTPDebug = 2; // Enable verbose debug output (print debug message)

$mail->isSMTP();

$mail->Host = 'relay-hosting.secureserver.net';

$mail->Port = 25;

$mail->SMTPAuth = false;

$mail->SMTPSecure = false;

?>

將 SMTPAuth、SMTPSecure 都設定 false,發信卻還是發生「SSL operation failed」、「certificate verify failed」的問題,要怎麼解決呢?

文章找到這個參數:$mail->SMTPAutoTLS = false;

原來現在 PHPMailer 已經預設啟用 TLS,所以程式修改如下:

$mail = new PHPMailer(true);

$mail->SMTPDebug = 2;

$mail->isSMTP();

$mail->Host = 'relay-hosting.secureserver.net';

$mail->Port = 25;

$mail->SMTPAuth = false;

$mail->SMTPSecure = false;

$mail->SMTPAutoTLS = false;

?>

於是就可以使用自己架設的 Mail Server 正常寄信囉~

Share this:

Print

相關

2015 年 04 月 27 日

在「Programming」中2013 年 10 月 07 日

在「Programming」中

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值