Receiving mail
Now, let's deal with the part of receiving mails.
Getting ready
In this recipe we will be giving examples on the different methods of connecting to mailbox through ZF2, and therefore it would be nice if we had access to a mailbox we connect to. Of course this is not required, but it sure adds to the fun to have an actual working mailbox.
How to do it…
We will now discuss receiving e-mail within an application, which can be useful on some occasions.
Connecting to an IMAP mail server
The first method of connecting to a mail server is through IMAP. The protocol basically lets us connect to the mail server, and looking in the different folders on the server if there are unread e-mails.
Let's take a look at our example:
<?php // Usually this sort of code is defined in the Model, // but to test it out we can place it in the // controller as well. namespace Application\Controller; // We need these classes to initiate an IMAP connection use Zend\Mail\Storage\Imap; use Zend\Mvc\Controller...