Tuesday, 19 December 2017

ZenCart Emails Fail to Send

I did an update of my Windows Server 2012 R2 with new versions of PHP (v.7.1.11) and ZenCart v1.56-Alpha.

A day ago I happened to login to the store admin area and noted there were 3 orders waiting to be dispatched but I was not notified.... oh dear.

Logging into the server via RDP and looking at the logs directory, showed me that I had a few

"SSL operation failed with code 1. OpenSSL Error"


"Email Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
in C:\Domains\ecufix.com\wwwroot\shop\includes\functions\functions_email.php on line 375"

Errors meaning that the emails were not being sent - double oh dear. To check, I logged into the ZenCart Admin console and altered the PayPal module settings and then a red banner appeared at the top of the browser telling me that there was an email sending error.

So something had changed either in PHP or ZenCart since the last time I used it. I know the ZenCart developers would never have let their code out of the door with a simple email bug. Therefore the error had to be related to PHP.

After a few hours of searching, I found the reason why emails were failing: essentially PHP now requires the CaCerts (Certificate Authority Certificates) defining in the OpenSSL section as well.

; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = "C:\Program Files (x86)\PHP\v7.1\Extras\SSL\cacert.pem"
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= "C:\Program Files (x86)\PHP\v7.1\Extras\SSL\cacert.pem"

This allows the emails to be sent again.

Remember, you can download the latest CA cert file from curl, install it somewhere accessible (for example c:/program files (x86)/php/v7.1/extras/ssl/cacert.pem) and point at it from the openssl.cafile and curl.cainfo directives in your php.ini file 

More info is available here: PHPMailer/wiki/Troubleshooting