Search code examples
phpemailgmailhtml-emailbitrix

Google mail insert pluses in the src path of images in html emails


My situation:
I'm sending html emails successfully. Styles, fonts and most of the images are shown as planned.

But some images from product previews became broken by google mail proxy scripts. There are around 6 images per email with 100x100px size each. Around 10% of them become broken - as no image at all at source (because + symbol appear in the address).

Checking code is helping me to only guess the reason, but not to fully fix it for me.

My src, that I send in email:

<img src="http://www.example.com/for_email/products_images/690/690xxxxxxx.jpg">

Google Mail changes it when showing to user to:

<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxxxxxx.jpg">

And all works good, but in 10% I have these broken links:

<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_e+mail/products_images/690/690xxxxxxx.jpg">
<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxx+xxxx.jpg">
<img src="https://ci5.googleusercontent.com/proxy/iyxxxuR-nG_Gst2xxxYN1-Qjxxx06hEE=s0-d-e1-ft#http://www.example.com/for_email/products_images/690/690xxxxxxx.j+pg">

Look at these pluses:

/for_e+mail/products_images/690/690xxxxxxx.jpg
/for_email/products_images/690/690xxx+xxxx.jpg
/for_email/products_images/690/690xxxxxxx.j+pg

What I try to fix it:

  1. Redirect. In adresses like this /for_email/products_images/690/690xxxxxxx.j+pg I just redirect to /for_email/products_images/690/690xxxxxxx.jpg after removing +. But it is not the solution for errors like /for_email/products_images/690/690xxx+xxxx.jpg because nginx work with such files and I will not change it for such minor reason.

  2. Less length. To fix this I also change images of names. Previously it was md5 hash like this.

    7c6a78c6ac5a6c56ac56a5c67ac5a6c57a65c67ac567a.jpg
    

    And now it is

    6657435previmg.jpg
    

    It helps to lower percentage of broken link to half, but not completely.

I have this problem for pretty much long time ago: around half year and occasionally try to solve it when have some spare time. Googling is still not helping me, I hope you do so.

I send it via PHP on 1C-Bitrix, but I don't think it matters (but not totally sure).


Solution

  • Have you looked at the encoded mail that your mail server sends out?

    In other words that what GMail actually receives? Simply send the same mail, using exactly the same method, to one of your own mailboxes, and use a tool to inspect the complete mail source.

    The reason I say this is because GMail usually inserts plus-signs when there's a space in the URL.

    You have to be absolutely sure it's not your end inserting them. Just looking at what you intent to send is not enough in this case.

    I can only guess why spaces would appear in your output. It all depends on how you send emails. Usually it is caused by a conversion or encoding/decoding.