'Cannot see the images in outlook

I have created a automatic mail with some texts,tables and charts. The charts are designed using quickcharts and used following method.

$chartConfig= "{
  type: 'line',
  data: {
    labels: [$date_array2],
    datasets: [{
      data: [$value_array2],
      backgroundColor: ['#F5DEB3'],
    }]
  },
  options: {
    title: {
      display: true,
      text: 'UGW Peak Throughput in Malabe_LD_vUGW, in Gbps',
    },
    legend: {
      display: false    
    }
  }
}";


$url1 = 'https://quickchart.io/chart?w=500&h=200&c=' . urlencode($chartConfig);  


$messagenew.= "Chart :<br><br><img src=\"$url1 \">

I am getting the email correctly. But the issue is I cannot see the chart directly. Every time I need to click download image to see the chart. Further I am using VPN connection to see the mails and I cannot see the images(even though it has downloaded). Without VPN connection I can see the images after downloading.

Can someone propose any better way to get charts attached to emails in PHP?



Solution 1:[1]

You need to add the image as an attachment and reference it in the HTML body of the email. See https://stackoverflow.com/a/17197140/332059

Solution 2:[2]

Web-hosted images can be blocked by Outlook automatically. Only users can unblock them in Outlook manually. To prevent such cases you can attach the required image and hide it from the view in Outlook by setting the PR_ATTACHMENT_HIDDEN property on the attachment:

Const PR_ATTACHMENT_HIDDEN As String = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"

Most probably you also need to set the PR_ATTACH_CONTENT_ID property in the code on the attachments to refer to such images in the message body:

Const PR_ATTACH_CONTENT_ID As String = "http://schemas.microsoft.com/mapi/proptag/0x3712001F"

And then from the message body you may refer to the property value (cid:) set earlier:

attachment = MailItem.Attachments.Add("c:\temp\chart.jpg")
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "YourChart1")
MailItem.HTMLBody = "<html><body>Test image <img src=""cid:YourChart1""></body></html>"

Read more about that in the Distinguish visible and invisible attachments with Outlook VBA thread.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitry Streblechenko
Solution 2 Eugene Astafiev