Opened 11 years ago
Last modified 6 years ago
#28059 new enhancement
Inline image attachments with wp_mail()
Reported by: | jesin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | 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)
Change History (7)
#3
follow-up:
↓ 4
@
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
@
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
@
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
.
Add inline images using
wp_mail()