PHP CodeIgniter 循环发送email邮件时出错 + curl证书

勾长卿
2023-12-01

        使用PHP CodeIgniter框架进行开发时发现,当循环发送38封邮件时出现以下错误,并且发送很少的几封邮件,上网查了很多资料,大多数人都使用了sleep(5)解决。但我使用sleep(5),甚至sleep(10)都无法将38封邮件全部发送成功,后来改为sleep(15)总算解决问题,但发送时间偏长,用了15分钟。最后,查询框架源代码和php手册,发现了解决办法,最终发送38封邮件仅用4分钟,并且没有提示错误。

一、开发环境:

   Apache/2.4.29 (Win64) OpenSSL/1.0.2n PHP/5.6.38


二、提示问题:

A PHP Error was encountered

Severity: Warning

Message: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1420C0CF:SSL routines:ssl_write_internal:protocol is shutdown

Filename: libraries/Email.php

Line Number: 2268

---------------------------------------------------

A PHP Error was encountered

Severity: Warning

Message: fwrite(): SSL operation failed with code 1. OpenSSL Error messages: error:1409E10F:SSL routines:ssl3_write_bytes:bad length

Filename: libraries/Email.php

Line Number: 2268

-----------------------------------------------------

三、问题解决:

Search 'fsockopen' from PHP Manual:

Trying to fsockopen an ssl:// connection, but it was hanging for a long time, ignoring timeout parameter, and eventually returning false, without an error message.

Turns out (at least) on Windows it validates certificates and doesn't have a valid certificate store.

This worked for me:

- download Mozilla's certificate store from https://curl.haxx.se/ca/cacert.pem
- copy it inside php installation (for example: c:\php)
- and set it up in php.ini
       
              openssl.cafile="c:\php\cacert.pem"

 类似资料: