how to get inbox messages from CPanel Webmail using PHP IMAP functions

1.8k views Asked by At

I'm integrating auto reply mail for unread messages in my cpanel webmail/roundcube/squirrelmail. See my code below here. The problem is i'm facing imap_open function is could not connected. It's loading can't through any error/ exception too still loading. Any one guide me. I'm looking forward for your reply. Also check my code is this correct or not.


    $emailAddress = '[email protected]'; // Full email address
    $emailPassword = 'xxxxxxxx';        // Email password
    $domainURL = 'example.com';         // Your websites domain
    $useHTTPS = false;                      

    /* BEGIN MESSAGE COUNT CODE */

    $inbox = imap_open('{'.$domainURL.':143/notls}INBOX',$emailAddress,$emailPassword) or die('Cannot connect to domain:' . imap_last_error());
    $oResult = imap_search($inbox, 'UNSEEN');

    if(empty($oResult))
        $nMsgCount = 0;
    else
        $nMsgCount = count($oResult);

    imap_close($inbox);

    echo('<p>You have '.$nMsgCount.' unread messages.</p>');
0

There are 0 answers