【问题标题】:Laravel email shows images fine in Mailtrap but not visible in GmailLaravel 电子邮件在 Mailtrap 中显示图像正常但在 Gmail 中不可见
【发布时间】:2021-04-23 13:49:59
【问题描述】:

我在下面使用了一个简单的 Laravel Mailable,并在电子邮件顶部显示标题图像 - 通过 Mailtrap.io 时显示正常,但在实时环境中将相同的电子邮件发送到我的 Gmail 帐户时它不会't display - 我做错了什么?

class TwoFactorMail extends Mailable
{
    use Queueable, SerializesModels;

    public $code;

    public function __construct($code)
    {
        $this->code = $code;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->markdown('emails.twofactor');
    }
}

刀片文件

@component('mail::message')
<html>
<head>
    <title>Two Factor</title>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins|Roboto&display=swap" rel="stylesheet">
</head>
<body>
<img src="data:image/png;base64,{{base64_encode(file_get_contents(resource_path('img/header.jpg')))}}" alt="">
        <h1 class="header padded-margin">Authentication code</h1><hr class="divider">
        <p>Your Two-Factor Authentication is below. Add the code into your browser to complete your CrowdControlHQ Sign In.</p>
        <div class="code padded-margin">{{ $code }}</div>
        <p>If you didn’t request this code there is nothing to worry about - you can safely ignore it.</p>
</body>
</html>
@endcomponent

【问题讨论】:

标签: php laravel laravel-mail mailtrap


【解决方案1】:

最好使用基于标准 url 的 src 作为您的图像标签。

只需确保您在 url 中包含域名,如下所示。

<img src="http://www.example.com/image.jpg" alt="img" />

大多数现代电子邮件客户端不接受 base64 图像。

您可以在这里阅读更多信息

https://blog.mailtrap.io/embedding-images-in-html-email-have-the-rules-changed/

搜索页面并阅读这两个主题

    1. 电子邮件中的内联嵌入或 base64 图像
    1. HTML 电子邮件中的链接图像或托管图片

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 2019-02-04
    • 2017-06-11
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多