Back to main menu


Growth email hacks: Dynamic images in emails

The best way to engage with your audience is to provide interesting and helpful content relevant to them. A highly tailored transactional email is a great avenue to obtain engagement success with your audience.



The best way to engage with your audience is to provide interesting and helpful content relevant to them. A highly tailored transactional email is a great avenue to obtain engagement success with your audience.

In this post, we’re going to look at how we can create dynamic elements in email to achieve just that.

If you are active in your social channels like Twitter and want to socialize your tweets beyond Twitter, why not include them in your newsletter or email digest to your audience? This could help you with open and click rates, improving your overall engagement rates.


If you’ve worked with emails before, you might be asking how it’s possible to alter the content of an email after it has been sent to a recipient. Or rather take advantage of inline attached images.

Email clients are instructed to fetch images from the given URL. Although some newer clients might cache the image, we can tell through specific HTTP headers to the proxy server to not cache the image.


We’re going to leverage the power of Mailgun through its PHP library. To do this, we will use PHP with the GD extension. For those of you who are not aware of the GD extension for PHP I suggest you read the guide on the official PHP site

  • A database of pre-approved tweets

  • PHP (With the GD extension)

  • PHP Mailgun Library

First Example:

Save the above to a file let’s say dynamicImage.php, place it in a public folder within your web server and then email someone (or yourself as a test):

You need to compose an HTML email with the image’s source specified as the public address to reach the dynamicImage.phpscript. Something like <img src="" > in the HTML body of the email should suffice to demonstrate the use-case..

Second example

Here we display through an image a random tweet from the list of approved tweets


As with every HTML email, remember to include a plain text fallback as this is always good practice.

This is a cool, simple trick to increase engagement and you can build on top of what you’ve learned in this article in hundreds of different scenarios like:

  • Show different offers depending on geolocalization of the user opening the email.

  • Display different content depending on the time the user opens the email

  • Is it raining? Is it sunny? As the user opens the email instantaneously customize the feel of the email with weather-aware images

  • Countdowns don’t have to suck anymore!

And probably my favorite idea:

  • Show queue position and status in support tickets

Let us know how you’re going to leverage dynamic images to your advantage.

Mail you later, Orlando

Sign Up

It's easy to get started. And it's free.

See what you can accomplish with the world’s best email delivery platform.

Related readings

What is DKIM: Learn how it works and why it’s necessary

Are you who you say you are, or are you a spoofer in disguise? Answering this question is what DKIM is all about. As email usage and capabilities continue to grow, it’s important to...

Read more

How to send transactional email in a NodeJS app using the Mailgun API

Sending transactional emails is easy regardless of your tools. If you use a NodeJS helper library, this walkthrough will help you get set up in Mailgun. Read more...

Read more

How does email work? Decode the mysteries with our straightforward guide

What is email? Well, we know it’s a cheap, effective form of communication that is so widely used there’s an entire global infrastructure to support it. We rely on email for...

Read more

Popular posts

Email inbox.

Build Laravel 10 email authentication with Mailgun and Digital Ocean

When it was first released, Laravel version 5.7 added a new capability to verify user’s emails. If you’ve ever run php artisan make:auth within a Laravel app you’ll know the...

Read more

Mailgun statistics.

Sending email using the Mailgun PHP API

It’s been a while since the Mailgun PHP SDK came around, and we’ve seen lots of changes: new functionalities, new integrations built on top, new API endpoints…yet the core of PHP...

Read more

Statistics on deliverability.

Here’s everything you need to know about DNS blocklists

The word “blocklist” can almost seem like something out of a movie – a little dramatic, silly, and a little unreal. Unfortunately, in the real world, blocklists are definitely something you...

Read more

See what you can accomplish with the world's best email delivery platform. It's easy to get started.Let's get sending
CTA icon