One possible solution is to inline the CSS styles in the HTML code instead of using an external stylesheet. This can be done using a tool like Premailer or by manually copying and pasting the CSS styles into the HTML code. Another solution is to use a service like Litmus or Email on Acid to test the email template across different email clients and devices to identify any compatibility issues. Additionally, it's important to ensure that the email template is optimized for mobile devices and that the images are hosted on a secure server with HTTPS.
Apr 13, 2023
1
Level 1
Mail Template CSS not Loading in Gmail Client
I'm trying to send an email using an email template like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="color-scheme" content="light">
<meta name="supported-color-schemes" content="light">
<title>{{ config('app.name') }}</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,200;0,400;0,600;0,800;1,200;1,400;1,600;1,800&display=swap" rel="stylesheet">
<style>
/* some style here */
</style>
</head>
<body class="font-sans antialiased font-medium bg-mail">
<div class="max-w-xl mx-auto">
{{-- more code here --}}
</div>
</body>
</html>
And this is how I'm sending the email:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class SendOrderDetail extends Mailable
{
use Queueable, SerializesModels;
/**
* The name of the theme that should be used when formatting the message.
*
* @var string|null
*/
public $theme = 'order-detail';
/**
* Create a new message instance.
*/
public function __construct()
{
//
}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
return new Envelope(
subject: 'Order Shipped',
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
return new Content(
markdown: 'emails.order-detail',
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
return [];
}
}
The email sending works fine, but the problem is with the email view that doesn't match expectations. The email template looks good when I test it with Mailtrap and Mailpit, but when I test it with Gmail, the CSS is not rendering correctly.
I am stuck here very badly. Any help will be appreciated, thanks in advance.
Please or to participate in this conversation.