Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tayyabshahzad1's avatar

Fetch email with headers

Hi, I am trying to get all emails with headers. for that I have tried

include_once('lib/class.imap.php');

$email = new Imap();
$connect = $email->connect(
	'{mail.my.property:143/notls}INBOX', //host
	'[email protected]', //username
	'pasword' //password
);
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
$inbox = $email->getMessages('html');
$data =  json_decode($inbox);
 //print_r($inbox['data']);
 foreach($inbox['data'] as $my_data) {
			print_r ($my_data);
};

Below is the response of the above code

Array
(
  
            [0] => Array
                (
                    [uid] => 27
                    [subject] => New Ticket
                    [date] => 2022-10-26 05:37:11am
                    [from] => Array
                        (
                            [address] => [email protected]
                            [name] => Support Ticket
                        )

                    [message] => This is the detail of email

                )

            

While sending the email I am setting a custom header, and when I receive an email I get that value in the email header, Using the above code I am getting all my inbox emails, But I also want header details as well Can you please help to fix this out thanks :)

0 likes
1 reply
click's avatar

Check the documentation or the code of this file include_once('lib/class.imap.php');, it is not a Laravel file.

Please or to participate in this conversation.