Working with email is easy in Php while there are few things that should be enabled before using it on your Ubuntu system.
On the list of those things there - IMAP.
IMAP - Internet Message Access Protocol
More can be learned on wikipedia - here.
On the way to use it in your Php application on Ubuntu machine you need to install it first by using this command on your terminal.
sudo apt-get install php-imap
After that restart your server like in case of Apache do run the command on terminal
sudo service apache2 restart
Then you are ready to go with IMAP.
In some cases we have found that after installing without any error it just can't work as desired and we get the error on the application.
The problem there is that IMAP is not enabled, Please check if it is enabled or not.
If not then you have to enable it manually like this for the first time only.
To enable it run command on your terminal as:
sudo php5enmod imap
After that restart your server like in case of Apache do run the command on terminal
sudo service apache2 restart
And then its way to fly on imap and explore.
Keep Learning :)