When having installed Magento 2 somewhere, you might encounter the following error in the frontend: We're sorry, an error has occurred while generating this email.. This guide helps you troubleshoot this issue.

Misleading message

Unfortunately, the error message itself is a bit misleading. It suggests that an error occurred while generating an email. However, this might not be the case - there might not even be an email involved. The reason for this is that the error is located in a part of Magento 2 where actually template filtering is used, while this filtering might be applied to email templates as well as CMS templates. The message is unclear. So we must do something to make the message clearer.

Enable developer mode

First of all, enable the developer mode to troubleshoot this error properly. This needs to be done from a command-line (SSH) using a command like this:

./bin/magento deploy:mode:set developer

Next, revisit the frontend again. The unclear message should now be replaced with a PHP error that most likely says something about a class Magento\Email\Model\Template\Filter. Possibly it also mentions something about the imagecreatefromjpeg function doing its job. If this indeed is the case, the rest of this guide might apply.

Missing JPEG support in GD

This error might be caused because JPEG support is missing in GD. First of all, your PHP environment should be shipped with GD support, which you can check for by creating a PHP info file:

<?php echo phpinfo();

If GD support is available, it might still be that JPEG support is missing. PHP GD support for JPEG is included in GD version 1.8 or later. But it also requires JPEG libraries to properly included on your system. If those JPEG libraries are missing, it might be that the function imagecreatefromjpeg is still available - proving that GD is there - but that the function actually fails to do anything. To check for GD JPEG support, create a file with the following contents and check for the JPEG flag:

<?php print_r(gd_info());

If GD is indeed missing JPEG support, you will need to recompile the PHP GD module to include the right JPEG libraries or perhaps you will need to recompile your entire PHP build. At least with this guide, you will know what to look for.

Posted on July 8, 2017

About the author

Author Jisse Reitsma

Jisse Reitsma is the founder of Yireo, extension developer, developer trainer and 3x Magento Master. His passion is for technology and open source. And he loves talking as well.

Sponsor Yireo

Upcoming events

Oct
28
Oct
31
LIEF Amsterdam

Looking for a training in-house?

Let's get to it!

We schrijven niet te commerciële dingen, we richten ons op de technologie (waar we dol op zijn) en we komen regelmatig met innovatieve oplossingen. Via onze nieuwsbrief kun je op de hoogte blijven van al deze coolness. Inschrijven kost maar een paar seconden.

Do not miss out on what we say

This will be the most interesting spam you have ever read

We schrijven niet te commerciële dingen, we richten ons op de technologie (waar we dol op zijn) en we komen regelmatig met innovatieve oplossingen. Via onze nieuwsbrief kun je op de hoogte blijven van al deze coolness. Inschrijven kost maar een paar seconden.