How to Put a Unique Coupon Code Inside Every Email Image

Sending the same discount code to fifty thousand people has a predictable outcome: within a day it is on a voucher aggregator site, and people who were never on your list are using it.

Unique codes solve that, but they create a production problem. One code per recipient means one image per recipient, and nobody is making fifty thousand images by hand.

You can generate them automatically from a single template - each image carrying that person's own code, rendered when they open the email. Here is how, along with the one implementation detail that quietly breaks redemption if you get it wrong.

Why put the code in the image at all

A code in plain text is trivially easy to harvest. Automated tools scrape promotional emails, extract anything that looks like a code, and publish it. Forwarding is just as easy - someone pastes it into a group chat and your one-per-customer offer becomes unlimited.

Rendering the code inside an image raises the effort considerably. There is no text to select, no string to regex out of an email body, and bulk harvesting requires OCR rather than pattern matching.

Be realistic about this. It is friction, not protection. OCR exists and is cheap. Someone determined will read the code and share it. What image-rendering does is stop casual, automated, at-scale harvesting - which is where most of the leakage happens. If you need genuine control, the enforcement has to be one-time-use codes on your commerce platform. The image is a deterrent layer, not a lock.

There is a second reason that has nothing to do with fraud. A code sitting inside a designed graphic, alongside the offer and the recipient's name, simply looks more deliberate than a string of characters in the body copy. It reads as something made for that person.

How it works

The mechanism is the same as any other personalized image. Your template has a dynamic text layer, and you pass the value in the URL:

https://media.okzest.com/img?c=YOUR-COMPANY-ID&i=YOUR-DESIGN-ID&name=Sarah&code=SAVE20-K4M9X

In the email, the values become your platform's merge tags:

<img src="https://media.okzest.com/img?c=YOUR-COMPANY-ID&i=YOUR-DESIGN-ID&name={{ first_name }}&code={{ discount_code }}"
     alt="Your personal discount code: {{ discount_code }}"
     width="600" />

One template, one image tag, a different code for every recipient. No batch generation and nothing stored.

The work is not in the image. It is in producing and tracking the codes.

Generating the codes

You need a unique code per recipient, and your commerce platform needs to recognise it. Three routes, depending on your setup.

From your ecommerce platform

Shopify, WooCommerce, BigCommerce and most others can generate batches of unique discount codes, usually exportable as a CSV. This is the cleanest route because the codes are valid in the system that will redeem them, and you can set one-time-use rules, expiry dates, and minimum spend at the point of creation.

Export the batch, then match codes to recipients in your email platform - usually by importing the codes as a custom field against each contact.

From your email platform

Klaviyo and some others can generate and assign unique codes natively, either drawing from an uploaded pool or integrating with your commerce platform to create them on send. If your platform supports it, this is the least manual option.

From a spreadsheet

Perfectly workable for smaller or one-off campaigns. Generate the codes in your commerce platform, put them in a sheet next to email addresses, import as a custom field.

Whichever route, generate more codes than you have recipients. New subscribers, resends, and the person who insists they never received it will all need one, and running out mid-campaign is an unpleasant problem to solve at speed.

The mistake that breaks redemption

Here is the detail that matters most, and it is the one most implementations miss.

A code that exists only inside an image cannot be copied. The recipient cannot select it, cannot paste it into your checkout, and if they are using a screen reader they cannot access it at all. On mobile, retyping a fifteen-character alphanumeric string from a picture into a checkout field is exactly the friction that ends a purchase.

Worse, images are blocked by default in many email clients, Outlook prominently. If your code lives only in the image, those recipients see an empty space where their offer should be.

Always put the code in text as well as in the image. The image is the presentation; the text is the mechanism. Something like:

<img src="...&code={{ discount_code }}" alt="Your discount code: {{ discount_code }}" width="600" />
<p>Your code: <strong>{{ discount_code }}</strong> - or <a href="https://yourstore.com/discount/{{ discount_code }}">apply it automatically</a></p>

That link is worth adding on its own merits. Most commerce platforms support a URL that applies a discount automatically, which removes the copying step entirely. It is the single biggest thing you can do for redemption rate.

Yes, this partly undoes the scraping resistance. That is the honest trade-off: a code nobody can use is not more secure, it is just useless. Put the code in text for usability, use one-time-use enforcement for control, and let the image do the work it is good at - making the offer feel personal and considered.

Designing a code that people can actually read

Codes are read character by character, which makes legibility matter far more than it does for a name.

Avoid ambiguous characters when generating codes. O and 0, I and 1 and l, S and 5, B and 8. Most code generators let you restrict the character set - do it. This single choice removes most redemption failures.

Use a font where the remaining ambiguity is visible. A monospace or clearly-drawn font beats a stylish one. This is not the place for personality.

Make it large and high contrast. The code is the most functional element in the image; it should be one of the most prominent.

Consider grouping. SAVE20-K4M9X is easier to read and retype than SAVE20K4M9X. Hyphens or spaces every four or five characters help significantly.

Design for the longest code your generator produces. Variable-length codes will overflow a layout built around a short example.

What to do about missing codes

Some recipients will not have a code - the field failed to populate, they were added after the batch, something went wrong in the import.

Set a fallback in the merge tag so the image renders something sensible rather than a blank space or the literal text {{ discount_code }}. A generic fallback code that still works, or wording that directs them to contact you, is far better than an image that looks broken.

Better still, suppress recipients with no code from the send. An email promising a personal discount that arrives without one is worse than not sending it.

Testing before you send

Codes have a failure mode that names do not: a wrong code is not just cosmetic, it costs a sale and generates a support ticket.

  • Redeem one yourself, end to end. Take a code from the actual batch, put it through your real checkout, and confirm it applies. Do this before every campaign, not just the first.
  • Check a long code and a short one if lengths vary.
  • Confirm the text version matches the image version. They are populated from the same field, but a typo in one merge tag will produce a mismatch that is very confusing for the recipient.
  • Test with images blocked to confirm the text fallback carries the offer on its own.
  • Check on mobile, where most people will be reading it.

Frequently asked questions

How do I generate thousands of unique coupon images for an email campaign? Build one image template with a dynamic field for the code, generate a batch of unique codes in your commerce platform, import them against your contacts as a custom field, then reference that field in the image URL. Each recipient's email renders their own code with no per-image work.

Does putting a code in an image stop people sharing it? It raises the effort. Codes in plain text are easily scraped by automated tools and published on voucher sites; codes rendered in an image require OCR. It is a deterrent against bulk harvesting rather than genuine protection. For real control, use one-time-use codes enforced by your commerce platform.

Should the code appear only in the image? No. A code only in an image cannot be copied, cannot be read by a screen reader, and disappears entirely when images are blocked. Always include it as text as well, and ideally a link that applies the discount automatically.

Which platforms can generate unique codes? Shopify, WooCommerce, BigCommerce and most commerce platforms generate batches of unique codes exportable as CSV. Some email platforms, Klaviyo among them, can generate or assign them natively.

What happens if a recipient has no code? Set a fallback value so the image does not render blank, and preferably suppress those recipients from the send. An email promising a personal discount that arrives without one causes more damage than not sending.

How do I stop codes being misread? Exclude ambiguous characters when generating them - no O/0, I/1/l, S/5, B/8 - use a clear font, render the code large, and group characters with hyphens.

Can the image show other personalized data alongside the code? Yes. The code is one dynamic field among however many you want - name, the product they viewed, their points balance, an expiry date. Each is another parameter in the same URL.

Can I use this for one-time-use codes? Yes, and you should. The image displays the code; your commerce platform enforces single use. Those are separate concerns and both are worth having.

Set up your first coded campaign

Start small. Generate fifty codes, send to a test segment, redeem one yourself, and check what proportion actually get used. That tells you whether the mechanics work before you point it at your full list.

OKZest renders personalized images from a single template - one URL, a different code for every recipient, generated when they open the email. It works with any email platform that supports custom image URLs and merge tags, and connects through Zapier or the API for automation.

Create a free account, no credit card required.


Related reading: put every recipient's name inside your email image, personalized images in Klaviyo, OKZest for ecommerce.