qferr / mjml-php

A simple PHP library to render MJML to HTML.
https://qferrer.medium.com/rendering-mjml-in-php-982d703aa703
67 stars 9 forks source link

Renderer seemed to suddenly stop working #7

Closed grandeljay closed 3 years ago

grandeljay commented 3 years ago

As the title mentions, rendering MJML doesn't seem to work anymore and I get this error. It stopped working on my live site too, so I can't help but wonder if recent core and plugin updates may be related to this.

[17-Dec-2020 11:30:53 UTC] PHP Fatal error:  Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) in /path/to/wp-plugin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:201
Stack trace:
#0 /path/to/wp-plugin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(155): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /path/to/wp-plugin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(105): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /path/to/wp-plugin[path here was truncated in log] in /path/to/wp-plugin/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 201

Any help would be greatly appreciated!

silas229 commented 3 years ago

It seems that your system has an outdated root certificate. Just use the internal rendering engine.

qferr commented 3 years ago

@silas229 I think so. @grandeljay your certificate on your server may be outdated or bad. You need to check it. Closing since this is not a bug.

djadomi commented 4 months ago

I know is very old (and closed) but for anyone getting here from a search…

For about the last 24 hours the MJML API has a cert problem again. This can be seen on a fully-upgrade Debian Bookworm system, with ca-certificates reinstalled and so on.

One work-around would be to add CURLOPT_SSL_VERIFYPEER => false and CURLOPT_SSL_VERIFYHOST => false to src/Http/CurlApi.php but for obvious reasons, it's not ideal.

Another option is to get Let's Encrypt's R3 cert:

curl -o /usr/local/share/ca-certificates/lets-encrypt-r3.pem https://letsencrypt.org/certs/lets-encrypt-r3.pem
ln -s /usr/local/share/ca-certificates/lets-encrypt-r3.pem /etc/ssl/certs/
update-ca-certificates

and update src/Http/CurlApi.php around line 53-ish:

...
$response = $this->curl->request($this->apiEndpoint . '/render', [
    CURLOPT_CAINFO => '/etc/ssl/certs/lets-encrypt-r3.pem',
    CURLOPT_RETURNTRANSFER => true,
...

Hopefully, this helps someone else. I'm probably going the route of self-hosting the API in the near future.