I’ve struggled for some time that embedded image(company logo) in my PHP generated emails didn’t show in Gmail. In some clients(e.g. Thunderbird), the logo showed without problem, however the same email didn’t display logo in Gmail Web, nor in Gmail App on my Android phone (Nexus 6).
Initially I thought this was a bug that Google needs to address as the logo showed correct in Thunderbird. After an extensive search and testing, I finally came with solution – To embed the image with the email itself!
Below is the code(PHPMailer)
$this->mail = new PHPMailer;
//attach logo within the email
then in email body part, ensure you use the same cid
<img src=”cid:MyLogo” alt=”Logo” style=”width:172px;height:96px;”>
Previously I used this code, it however doesn’t show the logo in Gmail.
src=”data:image/png;base64,<?php echo base64_encode(file_get_contents(‘CUALogo.png’)); ?>” width=”172″ height=”96″>
To sum up, there are 3 ways to embed images in email:
- Attach to email, this is the code showed above
- base64 encode images. This is the 2nd solution showed above, it however doesn’t always show images, especially in GMail
- Use external server. The images are however likely to be blocked by most email clients.