Question

How to get every subject of email with php imap?

<?php $hostname = ‘{imap.gmail.com:993/imap/ssl}’; $username = ‘xxx@gmail.com’; $password = ‘pass’; $inbox = imap_open($hostname,$username,$password); $nums=imap_num_msg($inbox); 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 ?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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 imap_fetch_overview call which includes the subject and basic header details.