| Recommend this page to a friend! |
| PHP MIME Email Message Parser | > | All threads | > | Decoded array problem | > | (Un) Subscribe thread alerts |
| |||||||||||||||
| 1 - 10 | 11 - 20 | 21 - 23 |
First off, I love this script. Nice Work Mr. Manuel!
I am having a problem with the following code in my slightly modified version of browse_mailbox.php: echo '<h2>MIME message decoding successful</h2>'."\n"; echo '<h2>Message structure</h2>'."\n"; echo '<pre>'; print_r($decoded[0]); echo '</pre>'; $address=$decoded['Headers']['envelope-to:']; print "email address = $address<br />"; This is part of the output when I run my script: Message structure Array ( [Headers] => Array ( [return-path:] => [envelope-to:] => [email protected] . . . enail address = Message analysis . . . The variable $address is blank. What is wrong with this line of code????? $address=$decoded['Headers']['envelope-to:']; Thanks so much! Jack
Are you sure it is blank?
Sometimes you dump the results to a Web page and everything between < and > is interpreted by the browser as an unknown tag, so nothing is displayed, but it is there is the page source.
Yes I am sure it is not there. I viewed the sources of the web page and here is the reult line below:
</pre>enail address = <br /><h2>Message analysis</h2>
I would need to process the same message you are seeing to advise.
I also need to know if you made any changes to the classes.
I have made no changes to teh core classes except for browse_mailbox.php.
Below is the code for browse_mailbox.php: <?php /* * browse_mailbox.php * * @(#) $Header: /home/mlemos/cvsroot/pop3/browse_mailbox.php,v 1.1 2008/01/09 07:36:25 mlemos Exp $ * */ ?><html> <head> <title>Parsing a POP3 email message</title> </head> <body> <center><h1>Parsing a POP3 email message</h1></center> <hr /> <?php require('mime_parser.php'); require('rfc822_addresses.php'); require("pop3.php"); /* Uncomment when using SASL authentication mechanisms */ /* require("sasl.php"); */ stream_wrapper_register('pop3', 'pop3_stream'); /* Register the pop3 stream handler class */ $pop3=new pop3_class; $pop3->hostname="mail.alhloghomes.com"; /* POP 3 server host name */ $pop3->port=110; /* POP 3 server host port, usually 110 but some servers use other ports Gmail uses 995 */ $pop3->tls=0; /* Establish secure connections using TLS */ $user="[email protected]"; /* Authentication user name */ $password="gizmo1251!"; /* Authentication password */ $pop3->realm=""; /* Authentication realm or domain */ $pop3->workstation=""; /* Workstation for NTLM authentication */ $apop=0; /* Use APOP authentication */ $pop3->authentication_mechanism="USER"; /* SASL authentication mechanism */ $pop3->debug=0; /* Output debug information */ $pop3->html_debug=1; /* Debug information is in HTML */ $pop3->join_continuation_header_lines=1; /* Concatenate headers split in multiple lines */ if(($error=$pop3->Open())=="") { echo "<PRE>Connected to the POP3 server "".$pop3->hostname."".</PRE>\n"; if(($error=$pop3->Login($user,$password,$apop))=="") { echo "<PRE>User "$user" logged in.</PRE>\n"; if(($error=$pop3->Statistics($messages,$size))=="") { echo "<PRE>There are $messages messages in the mail box with a total of $size bytes.</PRE>\n"; if($messages>0) { $i=1; while ( $i <= $messages ) { $pop3->GetConnectionName($connection_name); $message=1; $message_file='pop3://'.$connection_name.'/'.$i; $mime=new mime_parser_class; /* * Set to 0 for not decoding the message bodies */ $mime->decode_bodies = 1; $parameters=array( 'File'=>$message_file, /* Read a message from a string instead of a file */ /* 'Data'=>'My message data string', */ /* Save the message body parts to a directory */ /* 'SaveBody'=>'/tmp', */ /* Do not retrieve or save message body parts */ 'SkipBody'=>1, 'extract_addresses'=>1, ); var_dump($parameters); $success=$mime->Decode($parameters, $decoded); // $addresses=ParseAddressList($addresses,$addresses); var_dump($addresses); if(!$success) echo '<h2>MIME message decoding error: '.HtmlSpecialChars($mime->error)."</h2>\n"; else { echo '<h2>MIME message decoding successful</h2>'."\n"; echo '<h2>Message structure</h2>'."\n"; echo '<pre>'; print_r($decoded[0]); echo '</pre>'; $address=$decoded['Headers']['envelope-to:']; print "enail address = $address<br />"; if($mime->Analyze($decoded[0], $results)) { echo '<h2>Message analysis</h2>'."\n"; echo '<pre>'; // var_dump($results); echo '</pre>'; } else echo 'MIME message analyse error: '.$mime->error."\n"; } $i++; } } if($error=="" && ($error=$pop3->Close())=="") echo "<PRE>Disconnected from the POP3 server "".$pop3->hostname."".</PRE>\n"; } } } if($error!="") echo "<H2>Error: ",HtmlSpecialChars($error),"</H2>"; ?> </body> </html>
You are trying to retrieve the e-mail address of the envelope-to: header but the class does not parse it unless you add it to the address_headers variable like this:
$mime->address_headers['envelope-to:'] = 1;
Thanks for your patience. I Added your line of code beloe:
$parameters=array( 'File'=>$message_file, /* Read a message from a string instead of a file */ /* 'Data'=>'My message data string', */ /* Save the message body parts to a directory */ /* 'SaveBody'=>'/tmp', */ /* Do not retrieve or save message body parts */ 'SkipBody'=>1, 'extract_addresses'=>1, ); $success=$mime->Decode($parameters, $decoded); if(!$success) echo '<h2>MIME message decoding error: '.HtmlSpecialChars($mime->error)."</h2>\n"; else { $mime->address_headers['envelope-to:']=1; echo '<h2>MIME message decoding successful</h2>'."\n"; echo '<h2>Message structure</h2>'."\n"; echo '<pre>'; print_r($decoded[0]); print_r($address_headers); echo '</pre>'; $address=$decoded['Headers']['envelope-to:']; print "enail address = $address<br />"; and it did not work. What is the name of the array that contains the envelope-to: email address?
That is because you are adding the after you already called the Decode function.
Ok:
I switched the line before the decode $parameters=array( 'File'=>$message_file, /* Read a message from a string instead of a file */ /* 'Data'=>'My message data string', */ /* Save the message body parts to a directory */ /* 'SaveBody'=>'/tmp', */ /* Do not retrieve or save message body parts */ 'SkipBody'=>1, 'extract_addresses'=>1, ); $mime->address_headers['envelope-to:']=1; $success=$mime->Decode($parameters, $decoded); if(!$success) echo '<h2>MIME message decoding error: '.HtmlSpecialChars($mime->error)."</h2>\n"; else { echo '<h2>MIME message decoding successful</h2>'."\n"; echo '<h2>Message structure</h2>'."\n"; echo '<pre>'; print_r($decoded[0]); print_r($address_headers); echo '</pre>'; and I still am not sure of the name of the array that contains the extracted email addresses. Again, thanks for your patience!
When in doubt, check the documentation. It is ExtractedAddresses .
|
| 1 - 10 | 11 - 20 | 21 - 23 |
info at phpclasses dot org.
