We're sorry, an error has occurred while generating this email.
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.
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:
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.