PHP Classes

Cannot read sent mail

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Cannot read sent mail  >  (Un) Subscribe thread alerts  
Subject:Cannot read sent mail
Summary:Mail sent with your class for MIME sending cannot be read later.
Messages:8
Author:Jamin
Date:2008-01-29 20:28:35
Update:2008-02-15 17:46:03
 

  1. Cannot read sent mail   Reply   Report abuse  
Picture of Jamin Jamin - 2008-01-29 20:28:37
I'm using both this class, and your class for sending MIME email (http://www.phpclasses.org/browse/package/9.html), to make a MySQL-based webmail solution for our company.

Both classes, on their own, seem to work great. However, they don't seem to play well with each other. If I send an email, I use the send class's GetHeadersAndBody function to store a copy of the email in the "sent" folder. Unfortunately, whenever I then try to look at that email later, the parse class returns the "premature end of data" error.

This has happened with storing the headers and body separately, and also with storing them all as one string (using GetMessage, rather than GetHeadersAndBody).

Any thoughts as to why the parser class would not read messages created by the send class? Anyone else came up with this problem and figured out a way to fix it?

Thanks in advance for any help.

  2. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-01-29 22:56:51 - In reply to message 1 from Jamin
You need to concatenate the headers and the body using an additional line break between them.

  3. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Jamin Jamin - 2008-02-11 16:35:30 - In reply to message 2 from Manuel Lemos
Manuel,

Thank you for the reply. I've tried that, and it still doesn't seem to be working. Now it's giving me an "incomplete message body part" error.

Here is the code I'm using to try this, if it helps...

// Get/create raw headers and body for storage.
$send->GetHeadersAndBody($allHeaders, $allBody);
for ($rawHeaders="", $h=0, Reset($allHeaders); $h<count($allHeaders); $h++, Next($allHeaders)) {
$key = Key($allHeaders);
$rawHeaders .= $key . ": " . $allHeaders[$key] . "\r\n";
}

// Decode full message.
$read = new mime_parser_class;
$read->mbox = 0;
$read->decode_bodies = 1;
$read->decode_headers = 1;
$read->ignore_syntax_errors = 1;
$params = array("Data"=>$rawHeaders . "\r\n" . $allBody);
$read->Decode($params, $decoded);

  4. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-02-11 17:58:54 - In reply to message 3 from Jamin
It is hard to see without knowing what is coming out the MIME message class. Are you sure the GetHeadersAndBody function is not returning any errors? If not, can you paste a minimal example the causes that problem.

  5. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-02-14 03:22:52 - In reply to message 3 from Jamin
It is hard to tell without seeing what exactly you are feeding to MIME parser.

Can you paste here the whole message data string that you built before passing to the MIME parser class?

  6. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Jamin Jamin - 2008-02-14 16:36:14 - In reply to message 5 from Manuel Lemos
Manuel, here is a dummy email.

This is what came out after using GetHeadersAndBody... I converted the headers array into raw format (as in the above post), then did [b]$rawHeaders . "\r\n" . $allBody[/b] to get the following:

To: <[email protected]>
Subject: Testing
From: Jamin <[email protected]>
Reply-To: Jamin <[email protected]>
Sender: [email protected]
Errors-To: Jamin <[email protected]>
X-Mailer: http://www.phpclasses.org/mimemessage $Revision: 1.78 $ (mail)
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="798dc2234ddce217585463a3cb853a5f"


--798dc2234ddce217585463a3cb853a5f
Content-Type: text/plain; charset=ISO-8859-1

Testing

--798dc2234ddce217585463a3cb853a5f
Content-Type: text/html; charset=ISO-8859-1

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
Testing
</body>
</html>
--798dc2234ddce217585463a3cb853a5f--

  7. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-02-14 19:52:26 - In reply to message 6 from Jamin
I just pasted the message in a new file and passed the file name as parameter to the test_message_decoder.php script and it works fine as expected.

I wonder if it is not an issue with line breaks that vanishes once you pasted the message in the forum post.

Can you save the data to a file and upload it somewhere that I can download and test the data exactly as you are passing to the MIME parser class?

  8. Re: Cannot read sent mail   Reply   Report abuse  
Picture of Jamin Jamin - 2008-02-15 17:46:03 - In reply to message 7 from Manuel Lemos
Manuel,

I have no idea what happened, or what changed, but now it's just decided to start working again. Weirdest thing I've ever seen. I wish I knew what I was doing wrong before, but I guess all that matters is that it works now.

Anyway, thanks again for your help.

---Jamin