This is my php code
<?php
error_reporting(0);
// Multiple email account
$emails = array(
array(
'no' => '5',
'label' => 'inbox 1',
'host' => '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX',
'username' => 'xxx@gmail.com',
'password' => 'xxx'
),
array(
'no' => '2',
'label' => 'Inbox Email 2',
'host' => '{mail.domain.net:143/notls}INBOX',
'username' => 'mail2@domain.net',
'password' => 'xxxxxxxxxx'
)
);
foreach ($emails as $email) {
$read = imap_open($email['host'], $email['username'], $email['password']) or die('Cannot connect to yourdomain.com: ' . imap_last_error() . '</div>');
$array = imap_search($read, 'SUBJECT "123"');
if ($array) {
$html = '';
rsort($array);
foreach ($array as $result) {
$overview = imap_fetch_overview($read, $result, 0);
$message = imap_body($read, $result, 0);
$reply = imap_headerinfo($read, $result, 0);
//Now I want a json output like bellow structure
/*
"email no":"1",//from emails array
"email lebel":"label",//from emails arrey
"subject" :"mail_subject",
"date" :"full date time",
"message" :"messege",
"sent_from":"sender email"
*/
}
}
imap_close($read);
}
?>
I want json
output from fetched emails like the following structure:
"email no":"email no",
"email_label":"label",
"subject" :"mail_subject",
"date" :"full date time",
"message" :"messege",
"sent_from":"sender email"
I don't know how to do that, if anybody write a example code that will very helpful for me
I tested it to print as normal using this code:
echo $overview[0]->from;
echo $overview[0]->date;
echo $overview[0]->subject;
echo $reply->from[0]->mailbox.'@'.$reply->from[0]->host;
echo $message;
and this is the output:
sahidul islam Sun, 23 Jun 2019 12:54:32 +0800123sahid4745@gmail.com--0000000000008222fd058bf67e3a Content-Type: text/plain; charset="UTF-8" Thi is test message --0000000000008222fd058bf67e3a Content-Type: text/html; charset="UTF-8"
Thi is test message
this part of the message --0000000000008222fd058bf67e3a Content-Type: text/plain; charset="UTF-8" Thi is test message --0000000000008222fd058bf67e3a Content-Type: text/html; charset="UTF-8"
Thi is test message
may be be conflicting when output as json_encode
, How do I extract Thi is test message
from $message
?