php extracting text/plain from mail body
Asked Answered
P

2

6

this is the content of one mail read by imap_php library. I would extract the content-type text/plain; charset=ISO-8859-1 text:

{"data":"10/10/2011","regione":"pt","provincia":"pistoia","nome":"nome","tel":"12345","email":"mymailaddress","richiesta":"qualcosa"}

If I use imap_body($mbox, $result[0]) i have returned all the text in the box. If I use imap_fetchbody($mbox,$email_number,2); I have returned the text/html body message that i don't want.

--20cf301e2f27a218c204a88578aa Content-Type: text/plain; charset=ISO-8859-1 {"data":"10/10/2011","regione":"pt","provincia":"pistoia","nome":"nome","tel":"12345","email":"mymailaddress","richiesta":"qualcosa"}

--20cf301e2f27a218c204a88578aa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable {"data&= quot;:"10/10/2011","regione":"pt","provi= ncia":"pistoia","nome":"nome","tel&= quot;:"12345","email":"mymailaddress","r= ichiesta":"qualcosa"} --20cf301e2f27a218c204a88578aa--

So what I have to use if I want the text/plain body? Thanks.

Photojournalism answered 20/7, 2011 at 19:55 Comment(1)
If you have a look at the imap_fetchbody docs, you'll find this example that will probably be of use.Ankle
S
6

You need to use 1.1 as the section argument to fetch_body() For example:

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

How to use IMAP in PHP to fetch mail body content?

Strike answered 20/7, 2011 at 20:2 Comment(0)
P
5

You Can also try these

content-type:text/html

$message = imap_fetchbody($inbox,$email_number, 2);

content-type:plaintext/text

$message = imap_fetchbody($inbox,$email_number, 1);

More explanation about imap_fetchbody

Proteus answered 21/8, 2013 at 6:34 Comment(1)
I am falling-back to this if the 1.1 and 1.2 does not yield content.Avouch

© 2022 - 2024 — McMap. All rights reserved.