0

When I fetch a particular mail using imap in php, I get some some encoded text before the fetched mail. How can I remove the encoded part..??

For eg. --001a11c129bebb60d204f687b277 Content-Type: text/plain; charset=ISO-8859-1 Sir, I would like to request you to grant me the permission to use the CSE lab number 1 for the Polaris event we are organizing from 26th September to 28th September. Regards ABC -- Chinmay Joshi --001a11c129bebb60d204f687b277 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Sir, =A0=A0=A0=A0=A0=A0 I would like to request you to = grant me the permission to use the CSE lab number 1 for the Polaris event we are organizing from 26th September to 28th S= eptember. Regards ABC

<?php
 function hey()
{
    $con=mysqli_connect("localhost","root","","project 6 sem");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $result = mysqli_query($con,"SELECT * FROM data where pkey='Permission' and skey='lab'");

    while($row = mysqli_fetch_array($result))
    {
      echo $row['reply1_yes'] . " " . $row['reply2_yes'];
      echo "<br>";
      break;


    }
mysqli_close($con);
return;
}
?>
 <?php

$con=mysqli_connect("localhost",'root',"","project 6 sem");


if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  else
    echo "Database connected..</br>";
?>
<?php
/* connect to server */
$hostname= '{imap.gmail.com:993/ssl/novalidate-cert}';
$username = 'exid@gmail.com';
$password = 'fktgi';

/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');

        $count = imap_num_msg($inbox);

    if($inbox)
    {

     //Check no.of.msgs
     $num = imap_num_msg($inbox);
     $emails = imap_search($inbox,'ALL');
     rsort($emails);

     //if there is a message in your inbox
     if( $num >0 )
     {
        $body1=imap_body($inbox,$num);
        $body=explode(" ",imap_body($inbox,$num));
        $count=count($body);
        echo "$body1";
          //read that mail recently arrived
          for($i=1;$i<$count;$i++)
          {
            if($body[$i]=="lab")
            {
                // Check connection
                 echo hey();
                 break;
            }            
          }
     }



    }

     //close the stream
    imap_close($inbox);
?>   
<?php
    mysqli_close($con);
?>
  • That should not be the case... Indeed the mime part in a message are separated by such boundaries, but the "parts" should be fetched without. I suspect that the message is formatted in a slightly invalid way. But for this you would have to post the whole message source. – arkascha Apr 08 '14 at 15:37
  • 1
    Show the code that you're currently using. – Patrick Q Apr 08 '14 at 15:38
  • possible duplicate of [php extracting text/plain from mail body](http://stackoverflow.com/questions/6767676/php-extracting-text-plain-from-mail-body) – Patrick Q Apr 08 '14 at 17:04
  • Could this potentially have something to do with encoding? In the headers of the email it specifies `charset=ISO-8859-1`. – Nathan F. Aug 03 '20 at 17:08

1 Answers1

0
$message = imap_fetchbody($inbox,$email_number, 1.1);
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
JustPBK
  • 25
  • 3
  • Welcome to Stack Overflow. Code-only answers are discouraged on Stack Overflow because they don't explain how it solves the problem. Please edit your answer to explain what this does and how it answers the question, so that it is useful to the OP as well as other users also with similar issues. – FluffyKitten Aug 03 '20 at 19:53