How to get every subject of email with php imap?

June 16, 2015 1.1k views
PHP Email

$hostname = '{imap.gmail.com:993/imap/ssl}';
$username = 'xxx@gmail.com';
$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 ?

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.

Have another answer? Share your knowledge.