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.

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
michele
  • 26,348
  • 30
  • 111
  • 168
  • If you have a look at the [imap_fetchbody](http://php.net/manual/en/function.imap-fetchbody.php) docs, you'll find [this example](http://php.net/manual/en/function.imap-fetchbody.php#89002) that will probably be of use. – Mike Jul 20 '11 at 20:02

2 Answers2

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?

Community
  • 1
  • 1
serialworm
  • 761
  • 3
  • 13
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

Kailas
  • 3,173
  • 5
  • 42
  • 52