How to get every subject of email with php imap?

Posted June 16, 2015 5k views

$hostname = ’{}’;
$username = ’’;
$password = ‘pass’;
$inbox = imapopen($hostname,$username,$password);
echo $nums;

I want to read how many emails in my gmail ,but failed,the code can’t executed from my vps in digitalocean.
The error info is : imap_open(): Couldn’t open stream .
A friend tell me that the code is right to read email numbers in gmail ,maybe is the firefox problem.
Many web hosts block mail ports by default.

Which port will be opened when to get the email from gmail?How to check which status my port are in my digitalocean vps?
Does my digitalocean vps block the port ?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

We don’t block any incoming mail ports. Doing some searching, this blog post may be useful in fetching gmail messages.

This stackoverflow question outlines how to retrieve message bodies via php-imap.

To get the subject I would recommend replacing the imap_fetchbody call for an imapfetchoverview call which includes the subject and basic header details.