3

It's been a while that I'm trying to do a job that gets the emails from gmail, parses them and then puts the required data in the database, but I'm finding it hard to work with PHP MailParse which documentation is very poor. I tried MimeMailParser.class.php that I found on google code (that it use MailParse inside) but it doesn't work as expected (or maybe is my fault).

The situation: clients send emails on different mail addresses, and all these emails are forwarded to a unique email address. I have to get the emails on this central mailbox.

Objective: I want to parse the email BODY TEXT and BODY HTML, The script: using MimeMailParse:

$body = imap_body($imap_connection,$email_number);
$parser->setText($body);
$text = $parser->getMessageBody('text');
$html = $parser->getMessageBody('html');

The output of the $text like $body, The output of $html is empty.

using raw Mailparse:

$buffer = imap_body($imap, $i);
$mail = mailparse_msg_create();
$pro = mailparse_msg_parse($mail,$buffer);
$struct = mailparse_msg_get_structure($mail); 
print_r($struct); // this outputs always: 1
foreach($struct as $st) { 
    $section = mailparse_msg_get_part($mail, $st); 
    $info = mailparse_msg_get_part_data($section);   
    print_r($info);
}

Output:

Array
(
    [0] => 1
)
struct endArray
(
    [headers] => Array
        (
        )

    [starting-pos] => 0
    [starting-pos-body] => 48
    [ending-pos] => 4186
    [ending-pos-body] => 4186
    [line-count] => 93
    [body-line-count] => 91
    [charset] => us-ascii
    [transfer-encoding] => 8bit
    [content-type] => text/plain
    [content-base] => /
)

So how can I get the html body and the text body, using these library or other library(I hope they have some examples and documentations)

Tedi Çela
  • 544
  • 1
  • 8
  • 20

0 Answers0