If you’re wondering whether Noptin can embed images directly inside emails (instead of loading them from a URL), the short answer is: not by default.
Noptin sends emails using the standard approach adopted by most newsletter platforms — images are linked, not embedded. There’s also no built-in setting to switch images to Base64 or CID embedded formats.
Warning:
This guide includes custom code and is intended for developers. We do not offer customer support for custom code.
How Images Work in Noptin Emails
When you add an image to a Noptin email:
- The image is uploaded to your WordPress Media Library (or another hosted URL).
- The email contains standard HTML like:
<img src="https://yourwebsite.com/wp-content/uploads/image.jpg">
- The recipient’s email app downloads the image when they open the message.
This is the same method used by most major email marketing tools because it’s the most reliable across devices and inbox providers.
Why images aren’t embedded automatically
Embedding images directly into the email (using Base64 or CID attachments) might sound like a good idea, but it often creates more problems than it solves.
| Issue | Explanation |
|---|---|
| Email size increases quickly | Embedded images can make your email several times larger. Large emails are more likely to be clipped, delayed, or flagged by spam filters. |
| Deliverability can suffer | Unusually large or complex email structures can look suspicious to spam filters, even if your content is legitimate. |
| Client compatibility | Webmail clients in particular may ignore or strip embedded image data. |
| Performance | Linked images can be cached and served through CDNs, which often results in faster loading for recipients. |
Because of these tradeoffs, linked images remain the safest and most compatible option for newsletters
Embedding Images with Custom Code
While Noptin doesn’t support automatic image embedding, developers can modify outgoing emails by adding the following PHP code snippet to their site.
add_filter( 'noptin_post_process_email_content', 'custom_inline_email_images_base64', 150 );
function custom_inline_email_images_base64( $html ) {
if ( empty( $html ) || ! class_exists( 'DOMDocument' ) ) {
return $html;
}
libxml_use_internal_errors( true );
$doc = new DOMDocument();
$doc->loadHTML( $html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD );
$uploads = wp_get_upload_dir();
$baseurl = $uploads['baseurl'];
$basedir = $uploads['basedir'];
$images = $doc->getElementsByTagName( 'img' );
foreach ( $images as $img ) {
$src = $img->getAttribute( 'src' );
if ( empty( $src ) ) {
continue;
}
// Skip already inlined images
if ( strpos( $src, 'data:' ) === 0 ) {
continue;
}
// Skip tracking pixel
if ( strpos( $src, 'noptin_ns' ) !== false ) {
continue;
}
// Skip SVG
if ( preg_match( '/\.svg(\?|$)/i', $src ) ) {
continue;
}
$body = '';
$type = '';
// ---------- LOCAL UPLOAD IMAGE ----------
if ( strpos( $src, $baseurl ) === 0 ) {
$relative_path = str_replace( $baseurl, '', $src );
$file_path = realpath( $basedir . $relative_path );
// Ensure the file is inside uploads directory
if ( $file_path && strpos( $file_path, realpath( $basedir ) ) === 0 && file_exists( $file_path ) ) {
$body = file_get_contents( $file_path );
$type = wp_check_filetype( $file_path )['type'];
}
// ---------- REMOTE IMAGE FALLBACK ----------
} elseif ( preg_match( '#^https?://#i', $src ) ) {
$response = wp_remote_get(
$src,
array(
'timeout' => 10,
'redirection' => 3,
)
);
if ( is_wp_error( $response ) ) {
continue;
}
$body = wp_remote_retrieve_body( $response );
$type = wp_remote_retrieve_header( $response, 'content-type' );
}
if ( empty( $body ) || empty( $type ) ) {
continue;
}
// Only allow safe image types
$allowed_types = array( 'image/png', 'image/jpeg', 'image/gif', 'image/webp' );
if ( ! in_array( $type, $allowed_types, true ) ) {
continue;
}
// Size limit (~300KB)
if ( strlen( $body ) > 300000 ) {
continue;
}
$base64 = base64_encode( $body );
$data_uri = 'data:' . $type . ';base64,' . $base64;
$img->setAttribute( 'src', $data_uri );
}
return $doc->saveHTML();
}
Before going this route, make sure to test thoroughly across major email clients and monitor deliverability and email size.
Leave a Reply