bhavika bhavika - 6 months ago 67
PHP Question

Getting error while fetching emails via imap

i have problem in IMAP
i am writing below code to fetch inbox emails

$hostname = '{}INBOX';
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());

i am getting error

"message": "imap_open(): Couldn't open stream {}INBOX"

please let me know solution


According to the imap_open() documentation you need to provide a service flag if you are not using IMAP.

You are using port 110 which is for POP3, so you need to let imap_open() know about that by changing your connection string from

$hostname = '{}INBOX';


$hostname = '{}INBOX';