Make WordPress Core

Opened 11 years ago

Last modified 6 years ago

#28059 new enhancement

Inline image attachments with wp_mail()

Reported by: jesin's profile jesin Owned by:
Milestone: 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 11 years ago.
Add inline images using wp_mail()
28059.2.diff (1.9 KB) - added by jesin 9 years ago.
Update 28059.diff

Download all attachments as: .zip

Change History (7)

@jesin
11 years ago

Add inline images using wp_mail()

#1 @jesin
11 years ago

  • Keywords has-patch needs-testing added

#2 @chriscct7
9 years ago

  • Keywords needs-refresh added

@jesin
9 years ago

Update 28059.diff

#3 follow-up: @swissspidy
9 years 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
9 years 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@…
8 years 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.