Skip to content

Embedded images in emails not replaced in Blade templates when <img> tag spans multiple lines #56808

Description

@ndrez-outl1ne

Laravel Version

v12.25.0

PHP Version

8.3.20

Database Driver & Version

No response

Description

The regex used in replaceEmbeddedAttachments (Illuminate\Mail\Mailer.php)

/<img.+?src=[\'"]cid:([^\'"]+)[\'"].*?>/i

does not handle <img> tags that span multiple lines. This occurs frequently when long attributes cause the HTML formatter or editor to break the tag across lines. As a result, embedded images are not properly replaced in the rendered email, leaving them as raw cid: references.

Steps To Reproduce

  1. Create an e-mail template in Blade.
  2. Include an embedded image, e.g.:
<img src="{{ $message->embed(resource_path('img/logo.png')) }}"
     width="140" alt="Alt text" style="height:auto; max-width:100%;" />
  1. Ensure the <img> tag is split across multiple lines.
  2. Render the e-mail.
  3. Observe that unless the <img> tag is on a single line, it will not be replaced, and the output contains the raw cid: string.

Expected Behavior:
Embedded images should be correctly replaced even when <img> tags span multiple lines.

Actual Behavior:
If the <img> tag is broken across multiple lines, the regex fails to match, leaving the raw cid: reference in the output.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions