I am trying to send an email with HTML markup and a picture that is generated by a PHP script. But the recipient receives a letter without a picture (instead of a picture, an empty space). My letter looks like this:

<p>Какой-нибудь текст...</p> <p>Картинка:</p> <p><img src="http://mysite.com/img.php"></p> <p>Какой-нибудь текст...</p> 

In img.php the following code:

 $image = imagecreatetruecolor(50, 100); imagefill($image, 0, 0, 0x555555); header('Content-type: image/png'); imagepng($image); imagedestroy($image); 

If you open the link mysite.com/img.php , then the picture is displayed correctly. The letter itself contains the Content-Type: text/html . The recipient receives a letter, not even in spam, the text is displayed correctly, but instead of a picture, an empty space, and Firebug reports that the actual size of the picture is 1x1 px, although I specify a different size. Moreover, if I send a picture not from a php script, but simply from the server <img src="http://mysite.com/img1.png"> , then it is displayed at the recipient. But I need to send the generated image. Tell me what am I doing wrong?

    2 answers 2

    You must specify that the first part of the link is an http-server. Accordingly, you need to specify the scheme (http: or https :) for example http://mysite.com/img.php

    Reproduced the situation. The script that generates the image took your (one to one). The script is sending the following letter:

     <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> </head> <body text="#000000" bgcolor="#FFFFFF"> <img alt="" src="http://froloff.su/test1.php" width="23" height="23"> <br> <img alt="" src="//froloff.su/test1.php" width="23" height="23"> <br> <img alt="" src="froloff.su/test1.php" width="23" height="23"> <br> Test images </body> </html> 

    In the third picture, Yandex completely removed the src attribute. The rest are shown normally. Moreover, the picture is generated with dimensions of 50 × 100, and is proxied by Yandex in its original size.

    • Nothing has changed, did not help. - wep6ak
    • one
      Which mail client? - tutankhamun
    • Client from yandex.ru In the received letter, the picture looks like this: <img src="https://resize.yandex.net/mailservice?url=http%3A%2F%2Fmysite.com%2Fimg.php&amp;proxy=yes&amp;key=c8d2b76745cc544f6641f0c69b7f72b0"> - wep6ak
    • one
      And if you prescribe the size of the pictures in the tag img ? - tutankhamun
    • one
      There may be a problem in the server (for example, Yandex cannot reach your server). I repeated your php code and sent a letter to the box @ yandex.ru. The picture came in its normal form - tutankhamun

    Faced the same problem. Subtracted from the article https://habrahabr.ru/company/yandex/blog/206508/ the following

    If you use inline-pictures, then in img-src you need to enable the "data:" protocol.

    I used for this http://b64.io/ But the encoded images were not displayed in gmail. He simply deleted everything from src . Therefore, I left a direct link to src , and added a srcset with an encoded srcset .

     <img src='https://host/img.png' alt="img" srcset="data:image/png;base64,PD94.........jwvc3ZnPg==" style="display:block; height:38px; min-width:497.5px;"> 

    Also this method allows you to add svg to html email with a foldback for png . In src put a png image, and in srcset - svg .