Connecting to Email Servers with PHP imap_open
Imap library provided by php can be used to connect to your email accounts and handle functions like email reading,composing,forwarding..etc. You will have to install the imap library depending on your php installation. imap_open function is used to connect to email servers. It will open a imap connection to the specified email server.
Using the imap_open
// imap_open($mail_box,$email_username,$email_password,$imap_options); imap_open('{imap.example.com:993/imap/ssl}INBOX','email_address','email_password',OP_READONLY) or die('Cannot connect to imap server');;
$mail_box = imap server settings to connect(port,ssl,server name,floder to access)
$email_username = your email address
$email_password = your email password
$imap_options = allows you to specify the method you want to use (More details on http://php.net/manual/en/function.imap-open.php)
Connect to Gmail Inbox with Imap Settings
$gmail_inbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX','','password') or die('Cannot connect to gmail');
Connect to Yahoo Inbox with Imap Settings
$yahoo_inbox = imap_open('{imap.mail.yahoo.com:993/imap/ssl}INBOX','','password') or die('Cannot connect to yahoo');
Connect to AOL Inbox with Imap Settings
$aol_inbox = imap_open('{imap.aol.com:993/imap/ssl}INBOX','','password') or die('Cannot connect to aol');
Connect to Local Mail Server using localhost Imap Settings
$local_inbox = imap_open('{localhost:993/imap/ssl}INBOX','','password') or die('Cannot connect to example domain');
Connect to Custom Mail Server using Imap Settings
You may need to connect to your company mail server using this function. You need to provide correct imap server, ssl or tls enebled and correct port.Even you provide the correct details sometimes server will say certificate failure. In these situations you have to use the novalidate-cert option to allow access to the email server.
$local_inbox = imap_open('{imap.example.com:993/imap/ssl/novalidate-cert}INBOX','','password') or die('Cannot connect to example domain');
How to Use PHP Imap
PHP imap library is has fully featured email functions. You can create your own email client using imap functions provided by this library.In future posts i am
going to explain how to use imap functions using practical examples.
going to explain how to use imap functions using practical examples.
Leave a Reply