FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Parse emails





DanielXP
Im currently working on a PHP + POP3 email webbased email service.

I have coded almost all of the site but my headers are messing up.

Code:
$email = parse_email($email);


The $email variable is a array it includes all the headers and message.

Code:
function parse_email ($email) {
        // Split header and message
        $header = array();
        $message = array();

        $is_header = true;
        foreach ($email as $line) {
                if ($line == '<HEADER> ' . "\r\n") continue;
                if ($line == '<MESSAGE> ' . "\r\n") continue;
                if ($line == '</MESSAGE> ' . "\r\n") continue;
                if ($line == '</HEADER> ' . "\r\n") { $is_header = false; continue; }

                if ($is_header == true) {
                        $header[] = $line;
                } else {
                        $message[] = $line;
                }
        }

// Parse headers
$headers = array();
foreach ($header as $line) {
        $colon_pos = strpos($line, ':');
        $space_pos = strpos($line, ' ');

        if ($colon_pos === false OR $space_pos < $colon_pos) {
                // attach to previous
                $previous .= "\r\n" . $line;
                continue;
        }

        // Get key
        $key = substr($line, 0, $colon_pos);

        // Get value
        $value = substr($line, $colon_pos+2);
        $headers[$key] = $value;

        $previous =& $headers[$key];
}

$message = implode('', $message);

// Return array
$email = array();
$email['message'] = $message;
$email['headers'] = $headers;

        return $email;
}


Is the code I have to split the headers and the message.

So all the following work fine such as..

$email['headers']['From'] = the message sender
$email['headers']['Envelope-to'] = whos the message is for
$email['headers']['Date'] = date email sent
$email['headers']['Subject'] = subject

But when it comes to the message it works fine with my own send email script and orange email. But with hotmail and gmail the message is messed up with some headers in it.

$email['message'] = the code for the message

With Gmail i get this

Code:
------=_Part_177979_24935233.1188244633529
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

***Orig message i sent, how it should be***

------=_Part_177979_24935233.1188244633529
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

***Orig message i sent, how it should be***   ** Repeated **


------=_Part_177979_24935233.1188244633529--


And hotmail I almost get the same message.

I hope you can help me with my problem..

Daniel
roeenoy228
Its cant be the same var name to the function..

it means that:
$email = parse_email($email);

cant be $email here too:
function parse_email ($email) {
DanielXP
roeenoy228 wrote:
Its cant be the same var name to the function..

it means that:
$email = parse_email($email);

cant be $email here too:
function parse_email ($email) {


I don't see why not I do that all the time and it works fine
kv
Probably gmail and hotmail are structuring the email in different way. Try var_dump on the $email and see if the message is placed at a different position in the array.
Related topics
Co myslicie o mojej stronce??
Warning Emails
How to move emails from Outlook Express to GMail
Impossible parse error!
Domain Emails
Trouble figuring out a parse error
Parse error: syntax error, unexpected '{' in /home/frih/publ
php error ?[parse error]
Parse error - need help
New twist to fake PayPal emails
AOL not accepting emails
Automaticly Delete Emails
Problem with sending emails (sender address verification)
PHP Parse error on form handling - New to PHP
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.