When sending emails with images, external links to web hosting or a CDN are often used. This works fine, but images can be blocked by email clients or fail to load when hosting is temporarily offline.
With Content-ID (CID), you send images inline with the email. They are directly included in the email itself, keeping them always visible without being blocked.
What is Content-ID?
Content-ID is a technique to embed images directly in emails. Instead of loading images from an external URL, you add the image as part of the email itself.
You use Content-ID for example for:
- Email signatures: logos and profile photos
- Newsletters: headers, product photos and visual elements
Perfect to use in both transactional emails and broadcast emails.
How does it work?
Using Content-ID is simple. You add an image as an attachment with a unique content_id, and then reference this image in your HTML with cid:your-content-id.
An example with our PHP SDK:
$lettermint = new Lettermint\Lettermint('your-api-key');
$lettermint->email
->from('hello@yourdomain.com')
->to('customer@example.com')
->subject('Welcome to our service')
->html('
<h1>Welcome!</h1>
<img src="cid:company-logo" alt="Company Logo" />
<p>Thanks for signing up.</p>
')
->attach('logo.png', base64_encode(), 'company-logo')
->send();
In the example, you can see that the src of the image references cid:company-logo. This corresponds to the content_id we provide with the attachment. This way the email client knows which image should be displayed where.
Note: Without content_id, the image appears as a downloadable attachment. With Content-ID, it is displayed inline at the location where you want to place the image.
Besides PHP, Content-ID is also available in our other integrations such as Node.js, SMTP and via our API. All examples and possibilities can be found in the documentation.
Conclusion
With Content-ID, you are no longer dependent on external hosting. Images are sent directly and are always visible, even when email clients block external content.
- Images directly visible
- No hassle with hosting for external URLs
- Emails continue to work offline
For more information and integration examples, check out our documentation.