php imap - get body and make plain text
i am using the php imap function to get emails from a pop3 mailbox and
insert the data into a mysql database.
here is the php code:
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect:
' . imap_last_error());
$emails = imap_search($inbox,'ALL');
if($emails)
{
$output = '';
rsort($emails);
foreach($emails as $email_number)
{
$header=imap_headerinfo($inbox,$email_number);
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$toaddress=$header->toaddress;
$replyto=$header->reply_to[0]->mailbox."@".$header->reply_to[0]->host;
$datetime=date("Y-m-d H:i:s",$header->udate);
$subject=$header->subject;
//remove the " from the $toaddress
$toaddress = str_replace('"','',$toaddress);
echo '<strong>To:</strong> '.$toaddress.'<br>';
echo '<strong>From:</strong> '.$from.'<br>';
echo '<strong>Subject:</strong> '.$subject.'<br>';
//get message body
$message = (imap_fetchbody($inbox,$email_number,1.1));
if($message == '')
{
$message = (imap_fetchbody($inbox,$email_number,1));
}
}
it works fine, however on some emails in the body i get = in between
words, or =20 in between words. and other times the emails will just be
blank even though they are not blank when sent.
This only happens when coming from certain emails.
how can i get round this and just make the email completely plain text?
No comments:
Post a Comment