---
schema_version: "1"
id: bdcb6c15e00b59b8acaaaac5d4f8f8e7b84632b6928720c5df4ad23c164c7c13
title: Generate Barcodes in Emails with AMPscript
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/mktg/264-0-0/mc_ceb_generate_barcodes_in_emails.md
canonical_url: https://help.salesforce.com/s/articleView?id=mktg.mc_ceb_generate_barcodes_in_emails.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 983acd67ebbfe76e9f8180c4b149f7d1616dd894459e287dd968a620ac8f3edc
description: Use barcodes to create personalized messages, such as ticket purchase confirmation emails, in Marketing Cloud Engagement. Instead of using a barcode generator, use the AMPscript BarcodeURL function to automatically generate barcodes based on information from a recipient's profile.
products:
  - Marketing
  - Marketing Cloud Engagement
release: "264"
---
# Generate Barcodes in Emails with AMPscript

Use barcodes to create personalized messages, such as ticket purchase confirmation emails, in Marketing Cloud Engagement. Instead of using a barcode generator, use the AMPscript BarcodeURL function to automatically generate barcodes based on information from a recipient's profile.

## Create a Scannable E-Ticket Scenario

![Thank You](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_email-264-0-0-production-enus/a0b807ef-dfbb-412c-b26e-310d91f2d6df/images/icon_note.png)

Thank You Special thanks to [Trailblazer Karol Cholewa](https://trailhead.salesforce.com/trailblazer-community/users/0053000000CUjxB/feed?tab=feed) for contributing this content.

This scenario describes how to create confirmation emails that staff can scan at a registration point directly from a participant’s mobile phone.

As a marketer, you assign each attendee a unique ticket ID based on name and email address values captured from an online registration form. To collect this data, you can use smart capture in a CloudPages landing page. If your form isn’t integrated with Marketing Cloud Engagement, manually enter the information in a sendable data extension. Then, with Content Builder and code snippets, build a personalized confirmation email with the unique ticket ID encoded in a barcode image. When the online registration is complete, the event organizer sends the personalized barcode e-tickets to each recipient in the data extension.

## Sample Data Extension Structure

Set the email data extension field to EmailAddress and the other fields to 128-character Text.

    
| Email | SubscriberKey | FirstName | LastName | Barcode |
| --- | --- | --- | --- | --- |
| john@example.com | john@example.com | John | Doe | OKVKTZ0K9O |
| kim@example.com | kim@example.com | Kim | Smith | HYW1D8XXDU |
| ben@example.com | ben@example.com | Ben | Clark | 31FPTXMR6I |
| robert@example.com | robert@example.com | Robert | Williams | 0OAHFSCGG4 |

## AMPscript Code Snippet for the Email

For e-tickets scanned on mobile phones, this example uses the common Code128Auto, which supports alphanumeric ASCII characters. This barcode type is also narrow and high density, which encodes data with the fewest bars. This example adjusts the width to 300 pixels and height to 100 pixels. The barcode image is the default black and white as we recommend the highest contrast for fast mobile screen scanning. See the [AMPScript BarCodeURL function](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-barcode-url.html) for available barcode types, parameters, and examples.

```

%%[
  var @barcode, @ticket, @firstName, @lastName, @fullName
  set @ticket = AttributeValue("Barcode")
  set @fullName = Concat(@firstName," ",@lastName)
  set @barcode = BarcodeURL(@ticket, "Code128Auto", 300, 100)
]%%
```

## Barcode Sample for the Email Body

The BarcodeURL function generates a PNG image at the time of the email send. Use an image tag and set the source attribute to the function’s value.

```

<p>Name: %%=v(@fullName)=%%</p>
<p>Ticket Number: %%=v(@ticket)=%%</p>
<p><img src="%%=v(@barcode)=%%"></p>
```

## Final Result

![message\_with\_barcode](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-mktg-mc_email-264-0-0-production-enus/a0b807ef-dfbb-412c-b26e-310d91f2d6df/mc_email/images/barcode.jpg)

#### See Also

- [Create a Content Builder Email](https://help.salesforce.com/s/articleView?id=mktg.mc_es_create_content_builder_email.htm&language=en_US)
- [Create a Data Extension in Contact Builder](https://help.salesforce.com/s/articleView?id=mktg.mc_cab_create_a_new_data_extension.htm&language=en_US)
- [Create a Landing Page](https://help.salesforce.com/s/articleView?id=mktg.mc_cp_use_landing_pages.htm&language=en_US)