How to fix 502 Bad Gateway when sending a letter?

Hi all. Faced with the problem that when sending emails get a 502 error,
when you send html, that is
Mail::send('view', $data, $callback);
But don't get the error when sending raw text, like so
Mail::raw('Some text', $callback);

Error logs:
*20639 recv() failed (104: Connection reset by peer) while reading response header from upstream,
upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:"

WARNING: [pool site.com] 16813 child exited on signal 11 (SIGSEGV) after 51.029643 seconds from start


The problem a lot of googling, but have not decided(
If you need any extra logs, write about it.
June 3rd 19 at 20:59
2 answers
June 3rd 19 at 21:01
On timeout off.
Configure your email service provider.

If this is not your local provider, use queue and send emails from a background process.
The script is fast, milliseconds. - Haven_Rogahn88 commented on June 3rd 19 at 21:04
June 3rd 19 at 21:03
Configure the server to use less memory. In your "dmesg | tail” can be clearly seen that the server kills the process because it lacks memory.

Solutions include:

- reduction of pm.settings max_children in PHP-FPM
- allocate a larger swap file
- reducing the size of MySQL buffers.

In General the basic server configuration is not carried out. So the wait here can be what you want, before the problem of memory shortage is not solved.

Find more questions by tags PHPLaravelNginxPHP-FPM