2

In most of my emails, the image included may not be present. In such cases the broken image icon is displayed along with my alt text.

Problem Explanation: While sending an HTML email along with an <img> tag, at cases this image may not be there (404). As the image URL is dynamic, I cannot verify the existence of the image before sending the email. So it displays a broken image icon. I want to get rid of this icon.

JSFiddle

Code Snippet:

<img alt="NA" src="http://www.somerandomdomain.com/error.png" width="120"  >

I am need of a solution compatible with all major email clients.

  • Have tried onerror handler, but it does not work in email clients.
  • Also have tried text-indent: -9999px;, it works in Outlook but not in Gmail.
  • When the negative indent is changed to positive Outlook scrolls to the right which is a mess.

The solutions mentioned in possible duplicate, are for the web. But my question is clearly about the HTML emails, where JS and objects does not work like the solutions provided.

Community
  • 1
  • 1
Saravanan
  • 1,879
  • 2
  • 27
  • 30

1 Answers1

0

When generating email, check if that image exists (Example in PHP):

$url = 'http://www.somerandomdomain.com/error.png';
$headers = @get_headers($url);

if (strpos($headers[0],'200') !== false) {
    echo "<img alt='NA' src='{$url}' width='120'/>";
} 
Justinas
  • 41,402
  • 5
  • 66
  • 96