Images in mail can't open image - php

I've read several topic on images and mailing, but I simple can't figure this one out.
I'm sending mail with PHP to a user with an image, it delivers the mail, shows that there is a images, but that the images is broken.
Could someone look into my composed mail as it is received for any errors?
Before loading in this images, I checked its type by getimagesize and it says img/png
Any help or suggestions are appreciated.
Subject: Screenshot compare of project: xxx
Content-Type: multipart/mixed;
boundary="multipart_related_boundary"
To: xxx#gmail.com
From: xxx#gmail.com
Subject: Screenshot compare of project: xxx
X-Mailer: PHP/5.4.20
This is a multi-part message in MIME format.
--multipart_related_boundary
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<html>
<head>
<title>Screenshot compare of project: static</title>
</head>
<body>
<p>We have found: 1 differances</p>
<p>chrometestBodyText.jpg</p>
<img alt="diffchrometestBodyText" src="cid:multipart_related_boundarydiffchrometestBodyText" />
</body>
</html>
--multipart_related_boundary
Content-ID: <multipart_related_boundarydiffchrometestBodyText>
Content-Type: image/png;
name=diffchrometestBodyText.png
Content-Transfer-Encoding: BASE64

I decided to use PHPMailer library https://github.com/PHPMailer/PHPMailer

Related

Send HTML email with base64 image using Laravel as API

I'm working on a project that includes sending mails.
For the front-end I'm using VueJS and Laravel for the backend/API part.
There's a part where the user will compose his/her own email in a rich text editor(wysiwyg). Then when the user embeds some image in the said editor, then when I pass it to the API, the image source becomes a base64 encoded image, then when it sends to the email recipient, it just displays the plain base64 text as the image source.
<img src="data:image/png:base64,............" />
The question is how can I display that base64 image in the email, instead of showing plain text base64 text.
I have tried adding headers to the mail, but it seems to not work.
$swiftMessage = $message->getSwiftMessage();
$headers = $swiftMessage->getHeaders();
$headers->addTextHeader('Content-Transfer-Encoding', 'base64');
$headers->addTextHeader('Content-Type', 'multipart/alternative;');
$headers->addTextHeader('Content-Type', 'text/html; charset=ISO-8859-1');
Thanks in advance!
EDIT
If you guys wanna see the headers I received in the email, here it is
Content-Type: text/html; charset=utf-8
Content-Type: multipart/alternative;
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Transfer-Encoding: base64

Using Content-ID and cid for embedded email images in Thunderbird

I'm generating emails in a PHP application which attach multiple files to an HTML email. Some of the files are Excel spreadsheets, some of the files are company logos which need to be embedded in the HTML so they load by default using Content-ID and cid identifiers to refer to the attached images.
As far as I can see, my syntax is correct, but the images don't ever load inline (they are attached successfully, however).
From: email#example.com
Reply-To: email#example.com
MIME-Version: 1.0
Content-type: multipart/mixed;boundary="d0f4ad49cc20d19bf96d4adf9322d567"
Message-Id: <20150421165500.0A5488021B#server>
Date: Tue, 21 Apr 2015 12:54:59 -0400 (EDT)
--d0f4ad49cc20d19bf96d4adf9322d567
Content-type: text/html; charset=utf-8
Content-transfer-encoding: 8bit
<html>
Html message goes here, followed by email.<br/>
<img src="cid:mylogo" />
</html>
--d0f4ad49cc20d19bf96d4adf9322d567
Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=excelsheet.xlsx
Content-Description: excelsheet.xlsx
Content-Disposition: attachment;
filename="excelsheet.xlsx"; size=24712;
Content-transfer-encoding:base64
[base64 encoded string goes here.]
--b19e863e2cf66b40db1d138b7009010c
Content-Type: image/jpeg;
name="mylogo.jpg"
Content-transfer-encoding:base64
Content-ID: <mylogo>
Content-Disposition: inline;
filename="mylogo.jpg"; size=7579;
[base64 encoded string goes here.]
--b19e863e2cf66b40db1d138b7009010c--
Can anybody see an obvious reason why the image won't embed as expected?
EDIT
Note this behaviour isn't general to all email clients. So far only noted in Thunderbird.
I noticed two issues:
The MIME-boundary is inconsistent. For the first attachment it's d0f4ad49cc20d19bf96d4adf9322d567 and then b19e863e2cf66b40db1d138b7009010c is used. Thus, technically the second attachment is "part" of the first attachment.
If you replace all b19e863e2cf66b40db1d138b7009010c by d0f4ad49cc20d19bf96d4adf9322d567 Thunderbird correctly identifies the image attachment.
Use multipart/related instead of multipart/mixed. (see RFC2387)
A multipart/related is used to indicate that each message part is a component of an aggregate whole. It is for compound objects consisting of several inter-related components - proper display cannot be achieved by individually displaying the constituent parts. The message consists of a root part (by default, the first) which reference other parts inline, which may in turn reference other parts. Message parts are commonly referenced by the "Content-ID" part header. (see Wikipedia entry for MIME multipart/related)

Parse multi-part emails encoded in base64 utf8 using PHP

I have a multi-part message that I would like to decode (see below).
I'm able to use PHP's base64_decode function to decode normal emails, but it wont work for multi-part emails.
Is anyone aware of how to do this or know of any scripts available?
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
SGVsbG8sIEkgY2Fu4oCZdCBzZWVtIHRvIGdldCB0aGUgbGluayB0byB3b3JrIGFmZmVjdGl2ZWx5
IHRvIGVudGVyIGluIHRoZSBuYW1lcyBvZiBwZW9wbGUgdG8gc2VuZCB0aGUgc3VydmV5IHRvb+KA
pml0IHdvbuKAmXQgbGV0IG1lIGVudGVyIHRoZSBuYW1lcy4gQmUgZ3JlYXQgaWYgeW91IGNvdWxk
IGhlbHAgb3Igc2hvdWxkIEkganVzdCB3YWl0IGEgbGl0dGxlIHdoaWxlIHRvIGdhaW4gdGhlIGFj
Y2Vzcz8NCg0KUmVnYXJkcw0... etc
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVy
bjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idXJuOnNjaGVt
YXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6d29yZCIgeG1sbnM6bT0iaHR0cDovL3NjaGVtYXMubWlj
cm9zb2Z0LmNvbS9vZmZpY2UvMjAwNC8xMi9vbW1sIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv
VFIvUkVDLWh0bWw0MCI+DQo8aGVhZD4NCjxtZXRhIGh... etc
--_000_FBA91459E616EF4B8C1CCF54B389A283030E5EMX105CL01corpemcc_--
There is a PHP module called mailparse which can do the heavy lifting for you.
On top of that, check out this wrapper which will make it more easy to access the functions of the library.
We use the php module in our stack at mailparser.io and it works very reliable.
I found this library which does most of what I want (I made a few small customisations).
https://github.com/CaTzil/emailParser

How to include header image to a .ics file using php?

I am trying to create a .ics file to send meeting request using php. Everything is well so far but now I must add an image to the invitation as a header for the body of the message.
How can I add a header image?
I tried to create a meeting using outlook, attach an image to it and then save as .ics file but I get a warning that the attached file may not be view able by all mail clients.
I tried ti add this code but this did not work
Note I am trying to create the .ics file using php.
Thanks
Outlook is trying to add an image in the event. This is indeed not supported by standard iCalendar format.
But from what I understand you want to add an image in the email invitation that will go to each attendee. In that case, you simply replace the text/html bodypart in your invitation with a multipart/related containing a text/html bodypart and an image/xxx bodypart, and link the two with a content-id. See https://www.rfc-editor.org/rfc/rfc2392
To get a concrete example, send an invitation from a Yahoo Calendar as they do send images along with invitation.
Here is the type of MIME structure that they send:
Content-Type: multipart/mixed;
Content-Type: multipart/alternative;
Content-Type: text/plain;
Content-Type: multipart/related;
Content-Type: text/html;
... your html version, which will include the image as <img src="cid:someuniqueid"/>
Content-Type: image/gif;
Content-ID: <someuniqueid>
... your image
Content-Type: text/calendar; charset=utf-8; method=REQUEST
Content-Type: application/ics; name="invite.ics"

Read MIME data using PHP

I have a third party program which basically allows users to send email and then it displays it in the system. But the problem is that it is generating an output like this: I want to just take this data and format it to something presentable. I would like to avoid REGEX. Are there any options or standard ways of displaying the content below in a more presentable fashion. Basically I will associate everything below as $text and then call a function clean($text) of sorts.
> This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--B_3331365494_4098727
Content-type: text/plain;
charset="US-ASCII"
Content-transfer-encoding: 7bit
test
--B_3331365494_4098727
Content-type: text/html;
charset="US-ASCII"
Content-transfer-encoding: quoted-printable
<HTML>
<HEAD>
<TITLE>Test</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>test</SPAN></FONT>
</BODY>
</HTML>
--B_3331365494_4098727--
PEAR::Mail_mimeDecode is a great class to decode MIME messages. Once installed, you can use it as such:
$message = new Mail_mimeDecode($text);
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$messageStruct = $message->decode($params);
//messageStruct is now an array representing the message
// with all the parts properly included.

Categories