WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 18 months ago

#28059 new enhancement

Inline image attachments with wp_mail()

Reported by: jesin Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Mail Keywords: has-patch needs-testing needs-unit-tests
Focuses: Cc:

Description

To insert inline images in an email the phpmailer_init action hook has to be used like this.

add_action( 'phpmailer_init', 'embed_images' );

function embed_images( &$phpmailer ) {
    $phpmailer->AddEmbeddedImage( '/path/to/image1.png', 'image1.png' );
    $phpmailer->AddEmbeddedImage( '/path/to/image2.png', 'image2.png' );
    $phpmailer->AddEmbeddedImage( '/path/to/image3.png', 'image3.png' );
}

Why not implement this in wp_mail() itself?

Attachments (2)

28059.diff (1.8 KB) - added by jesin 4 years ago.
Add inline images using wp_mail()
28059.2.diff (1.9 KB) - added by jesin 2 years ago.
Update 28059.diff

Download all attachments as: .zip

Change History (7)

@jesin
4 years ago

Add inline images using wp_mail()

#1 @jesin
4 years ago

  • Keywords has-patch needs-testing added

#2 @chriscct7
2 years ago

  • Keywords needs-refresh added

@jesin
2 years ago

Update 28059.diff

#3 follow-up: @swissspidy
23 months ago

  • Keywords needs-unit-tests added; needs-refresh removed

According to the docs, $phpmailer->addEmbeddedImage is only useful for HTML messages. What happens when you use that in a text email?

#4 in reply to: ↑ 3 @jesin
23 months ago

Replying to swissspidy:

According to the docs, $phpmailer->addEmbeddedImage is only useful for HTML messages. What happens when you use that in a text email?

In a text message the email client shows the image as an attachment. I tested this on Gmail and Outlook.com.

#5 @chris@…
18 months ago

I'm not sure if this is needed at the wp_mail level or not (although I needed to do the workaround today) but if this gets refreshed I wouldn't blindly assume that basename( $embed ) is valid for the $cid parameter.

Most people probably have image-1.png and image-2.png but it could be http://example.com/cats/logo.png and http://example.com/dogs/logo.png and basename() would turn them both into logo.png.

Note: See TracTickets for help on using tickets.