How can I display email content on a website?

I would like to display the contents of the body of the email. I tried IMAP in php, but something is VERY wrong. IMAP does not collect the text of my message. He selects ONLY the signature in the body. Therefore, I am looking for alternative methods for reading the contents of the email body on a web page.

here is the original document of my letter:

http://pastebin.com/WQra335P

disclaimer / copyright violation is captured by IMAP, but nothing else is displayed in the body. Does anyone have alternative methods of reading email from gmail or any other site that can display content on a web page?

I refused to let IMAP read it because no one could understand the problem ... I spent hours, so I give up, but here is the code ...

<?php /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = ' username@gmail.com '; $password = 'password'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'ALL'); /* if emails are returned, cycle through each... */ if($emails) { /* begin output var */ $output = ''; /* put the newest emails on top */ rsort($emails); /* for every email... */ foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($inbox, $email_number, 0); $message = imap_fetchbody($inbox, $email_number, 2); echo $message; echo imap_qprint($message); $message = imap_qprint($message); echo imap_8bit ($message); $DateFormatted = str_replace("-0500", "", $overview[0] -> date); /* output the email header information */ $output .= $overview[0] -> subject ; $output .= $DateFormatted ; //$bodyFormatted = preg_replace("/This e-mail(.*)/","",$message); //$bodyFormatted = preg_replace("/Ce courriel(.*)/","",$bodyFormatted); /* output the email body */ $output .= $message; } echo $output; } /* close the connection */ imap_close($inbox); ?> 
+4
source share
4 answers

In addition to Dmitry’s proposal,

The addendum below does everything perfectly, without the occasional "=" signs. Str_replace is used to remove generated "=" pages.

 $message = imap_fetchbody($inbox, $email_number, "1.1"); $message = str_replace("=", "", $message); 

I don’t know 100% why "=" is generated randomly, but this is most likely due to some encryption problem from the Exchange server, since our server is about 10 years old.

+2
source

You are dealing with multicast messages (looking at your pastebin email sample). Try this line as a test:

 $message = imap_fetchbody($inbox, $email_number, "1.1"); 

The plain text version lives under 1.1. The HTML version is 1.2. The signature is in the next part - this is 2. And this is what you extract in your sample code.

+2
source

Gmail has several different IMAP settings, more carefully follow the source code:

http://davidwalsh.name/gmail-php-imap

0
source

You have access to raw email content (material with all headers, etc.).

If so, try using plancacke email parser

I have used it with success.

 $emailParser = new PlancakeEmailParser(...raw email content...); $emailTo = $emailParser->getTo(); $emailSubject = $emailParser->getSubject(); $emailCc = $emailParser->getCc(); $emailDeliveredToHeader = $emailParser->getHeader('Delivered-To'); $emailBody = $emailParser->getPlainBody(); $emailHtml = $emailParser->getHTMLBody(); 
0
source

Source: https://habr.com/ru/post/1384392/


All Articles