Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix deprecations for embedded images in symfony mailer #46488

Merged

Conversation

Jubeki
Copy link
Contributor

@Jubeki Jubeki commented Mar 16, 2023

Fixes #46462

It seems like Symfony has deprecated the old way of embedding images in Mails since 6.2:
https://symfony.com/doc/current/mailer.html#embedding-images

This PR implements the new way of embedding images.

@Jubeki Jubeki marked this pull request as ready for review March 16, 2023 13:45
Copy link
Member

@driesvints driesvints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm in general 👍

@Jubeki have you tried out a few scenarios with Helo or something similar?

@Jubeki
Copy link
Contributor Author

Jubeki commented Mar 17, 2023

@Jubeki have you tried out a few scenarios with Helo or something similar?

I used Mailhog with the following code example (and an image stored in storage/app/profile.jpg) and it showed the image inline. I did not try it with any other email provider, but can try it out with ses if wanted.

// app\Mail\TestMail.php

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: 'Test Mail',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'test',
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
{{-- resources/views/test.blade.php --}}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p>TEST E-Mail</p>
    <img src="{{ $message->embed(storage_path('app/profile.jpg')) }}" alt="" style="height: 100px; width: 100px;" />

    <img src="{{ $message->embedData(file_get_contents(storage_path('app/profile.jpg')), 'profile2.jpg') }}" alt="" style="height: 100px; width: 100px;" />
</body>
</html>

@driesvints
Copy link
Member

perhaps best indeed that we try it out with ses as well. Also maybe try a data attachment?

@Jubeki
Copy link
Contributor Author

Jubeki commented Mar 17, 2023

@driesvints

I updated the above example to also test the embedData method.

Both work with Mailhog and SES.

@taylorotwell taylorotwell marked this pull request as draft March 17, 2023 13:41
@taylorotwell taylorotwell marked this pull request as ready for review March 17, 2023 14:27
@taylorotwell taylorotwell merged commit 2cd749d into laravel:10.x Mar 17, 2023
@taylorotwell
Copy link
Member

Thanks

@Jubeki Jubeki deleted the fix-symfony-mailer-embedded-deprecations branch March 19, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[10.x] Mail-component uses embed-syntax deprecated with Symfony Mailer 6.2
4 participants