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
- Create an e-mail template in Blade.
- 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%;" />
- Ensure the
<img> tag is split across multiple lines.
- Render the e-mail.
- 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.
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:([^\'"]+)[\'"].*?>/idoes 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 rawcid:references.Steps To Reproduce
<img>tag is split across multiple lines.<img>tag is on a single line, it will not be replaced, and the output contains the rawcid: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 rawcid:reference in the output.