Page 1 of 1

getting just the HTML

Posted: Fri Jan 26, 2007 8:12 pm
by jackbravo
Hi, I'm using swift to send an email with a PDF attachment and html format.

Using Gmail i see my email perfectly. But when using hotmail or outlook the emails sometimes (and not always) are wrong. The email is recieved (sometimes as spam, and I'm sending it from a hosted email account). But you can see the Mime headers and the PDF attachmet as a bunch of characters.

This is the code I use to send the email (all my files are in iso-8859-15 encoding):

Code: Select all

$mail->addPart($body, 'text/html', 'iso-8859-15');
            $mail->addAttachment(file_get_contents("../pdf/docs/{$proyecto->id}.pdf"), 'Proyecto.pdf', 'application/pdf');
            $mail->send($to, $_SESSION['user']->getEmail(), $_POST['subject']);
            $mail->close();
Any thoughts?

Wrong email recieved follows:
-----------

X-Mailer: Swift 2.1.17 by Chris Corbyn
Reply-To: <adpro@adventa.com.mx>
Subject: Cotizacion #23
Date: Fri, 26 Jan 2007 17:56:03 -0600
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="_=_swift-2877655045ba95132d9fb2.04412545"
Content-Transfer-Encoding: 8bit
From: Asesor Tres <sistemas@opengate.com.mx>
Message-ID: <45ba98e9.69bbb813.5757.ffffa811@mx.google.com>
X-OriginalArrivalTime: 27 Jan 2007 00:12:26.0960 (UTC)
FILETIME=[D3A68D00:01C741A7]

This part of the E-mail should never be seen. If
you are reading this, consider upgrading your e-mail
client to a MIME-compatible client.
--_=_swift-2877655045ba95132d9fb2.04412545
Content-Type: multipart/alternative;
boundary="_=_swift-121085068345ba95132da384.02698895"

--_=_swift-121085068345ba95132da384.02698895
Content-Type: text/html; charset="ISO-8859-1"; format=flowed
Content-Transfer-Encoding: 8bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang=es>
<head>
<title>ADPRO</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15">
<link href='http://lcaguirre.opengate.com.mx/PhpMailer/screen.css'
rel='stylesheet' type='text/css' />
<link href='http://lcaguirre.opengate.com.mx/PhpMailer/estilo.css'
rel='stylesheet' type='text/css' />
</head>
<body>
<table border='0'>
<tr>
<td><img
src='http://lcaguirre.opengate.com.mx/PhpMai ... png'/></td>
</tr>
<tr>
<td> <h3><br />Lic. ALMA VILLANUEVA</h3> <p>Anexo encontrar&aacute; la
cotizaci&oacute;n de art&iacute;culos que amablemente nos solicit&oacute;.
Espero encuentre en el documento anexo, los art&iacute;culos que cubran
perfectamente su requerimiento, presupuesto y el tiempo de entrega sea el
adecuado para ud. quedo a sus respetables &oacute;rdenes para cualquier
informaci&oacute;n adicional.</p> <p>Atentamente;</p> <h3>Asesor Tres<br />
Ejecutivo de Marcas</h3> <hr /> <p>No dejes para ma?ana lo que puedes hacer
hoy</p> </td>
</tr>
</table>
<h1>&nbsp;</h1>
</body>
</html>
--_=_swift-121085068345ba95132da384.02698895--


--_=_swift-2877655045ba95132d9fb2.04412545
Content-Type: application/pdf; name="Proyecto.pdf";
Content-Transfer-Encoding: base64
Content-Description: Proyecto.pdf
Content-Disposition: attachment; filename="Proyecto.pdf"

JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNlcyAy
IDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0ZsYXRlRGVj
b2RlIC9MZW5ndGggNjUwPj4Kc3RyZWFtCniclVVNT9wwEL3zK+bYSmBiO3Gyt6YQ0La7tIUU9ep1
......

Posted: Sat Jan 27, 2007 12:08 am
by superdezign
You mean using the exact same code, it's fine in Gmail, but not hotmail? Then maybe your error message is right. :-p
This part of the E-mail should never be seen. If
you are reading this, consider upgrading your e-mail
client to a MIME-compatible client.

bad hotmail... bad

Posted: Mon Jan 29, 2007 4:33 pm
by jackbravo
hehehe

well, while I agree that hotmail is not the best MIME-Client, I have to do something about it. Especially because is not just hotmail, but also Outlook users, the ones who get the email wrong. And many people who will be using my system are hotmail or outlook users :(

Posted: Wed Jan 31, 2007 6:54 am
by Chris Corbyn
Could it be that Hotmail doesn't like the charset you're using?

Where do you define $body?

Maybe

Posted: Wed Jan 31, 2007 9:59 am
by jackbravo
d11wtq wrote:Could it be that Hotmail doesn't like the charset you're using?

Where do you define $body?
It may be so. I've been fighting with the charsets of my project files for some time. $body is defined on the same file that sends the emails. I use a textarea with tinyMCE that has some default text. The file itself is iso-8859-15.

Re: getting just the HTML

Posted: Wed Jan 31, 2007 10:38 am
by Chris Corbyn
FILETIME=[D3A68D00:01C741A7]

I have a feeling that line is messing up hotmail and outlook. Rightly so... it's not valid. Because it's part of the headers it has to either start with a blank space or tab, or be a correctly defined header in the form "Header-name: value".

Swift doesn't add that line, so I'm not sure where it comes from. If a server is adding it then it is not doing a very good job ;)

I think I got it

Posted: Wed Jan 31, 2007 10:49 am
by jackbravo
I think the problem is finally solved.

While trying the application I noticed that some e-mails arrived OK while others not. I found that the diference was that the emails that arrived wrong had a CC value, while the others didn't. This was the problem, when I parsed the CC field of my form, with something similar to

explode(',', $_POST['cc')

I ended up with a cc like:

array( "some@email.com", "");

And that was it. So watch out for that one folks. Make sure your CC, to and, bcc values don't have any spaces or empty values or some email clients (hotmail, outlook) won't like it.

Re: getting just the HTML

Posted: Wed Jan 31, 2007 10:52 am
by jackbravo
d11wtq wrote:FILETIME=[D3A68D00:01C741A7]

I have a feeling that line is messing up hotmail and outlook. Rightly so... it's not valid. Because it's part of the headers it has to either start with a blank space or tab, or be a correctly defined header in the form "Header-name: value".

Swift doesn't add that line, so I'm not sure where it comes from. If a server is adding it then it is not doing a very good job ;)
Hmmmmmm, that's odd. Maybe that has something to do with the problem also. I was posting my findings while you posted this. Where on the process could that line had been added? On PHP, or by the http server? the smtp server?

Posted: Wed Jan 31, 2007 11:00 am
by Chris Corbyn
I haven't written any tests for it but I believe blank Cc values will be ignored in version 3, or if they're not, they'll be turned into valid <> null envelopes. I'll write some tests to prevent this problem though :) I'm actually sat working on the library as we speak... ermm... write.

Posted: Wed Jan 31, 2007 1:46 pm
by jackbravo
Great! Thank you very much. Hopefully in future version this won't be an issue.

On a side note. I like better the EasySwift (old swift) api. The new one, altough maybe easier to maintain, feels complicated. We will be porting to Swift 3 shortly, and probably using EasySwift, so we can provide you with some feedback.

Great Library. Many thank you's =P