Modifying the Content-Disposition header to inline for embedded images may fix this issue. You can do this by creating a custom Mailer class that extends the Symfony Mailer class and overrides the createAttachment
method to set the correct header for inline images.
Below is a mailer class example:
namespace App\Mail;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\InlinePart;
use Symfony\Component\Mime\Part\PartInterface;
use Symfony\Component\Mime\Attachment\Attachment;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Message;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Illuminate\Contracts\Mail\Mailer as MailerContract;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailer as BaseMailer;
class Mailer extends BaseMailer implements MailerContract
{
/**
* Create a new message instance.
*
* @return \Symfony\Component\Mime\Message
*/
protected function createMessage()
{
$message = new Email();
$this->addContent($message);
return $message;
}
/**
* Create a new attachment.
*
* @param string|\Symfony\Component\Mime\Part\PartInterface $file
* @param array $options
* @return \Symfony\Component\Mime\Attachment
*/
public function createAttachment($file, array $options = [])
{
if ($file instanceof PartInterface) {
return new InlinePart($file->body(), $file->getHeaders());
}
$attachment = Attachment::fromPath($file);
if (isset($options['filename'])) {
$attachment->filename($options['filename']);
}
if (isset($options['mime'])) {
$attachment->contentType($options['mime']);
}
if (isset($options['disposition'])) {
$attachment->disposition($options['disposition']);
}
return $attachment;
}
}
Change settings in config/mail.php
like below to use custom mailer class.
'mailer' => env('MAIL_MAILER', 'smtp'),
'smtp' => [
'transport' => 'smtp',
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'timeout' => null,
'auth_mode' => null,
],
'pretend' => false,