Search code examples
phpemailimap

Using PHP with IMAP to check POP3 "syntax error"


I am trying to connect to a pop3 email account that is hosted by my website host. My website is a shared host. The email host that I check my emails with windows live is mail.mysite.com with port 110 and it works fine.

Using php and imap I have not had any luck. I did check and my host does have IMAP installed. After that I fought with it for a few hours and learned when imap_open fails it tries 3 more times just for fun. As I started with imap_last_error() as my error checker it was telling me Cannot connect to Mail: Too many login failures Once I figured out what was happening it did not take long to figure out how to get the rest of the errors and then how to turn it off so it does not retry.

Now I am getting syntax error I have tried dozens and dozens different variations of hostname. Below I include 4 so people can see some of the saner things I have tried and the results.

As I am completely new to this I am likely missing something obvious to someone with more experience. I am also open to other ways to go about this. I just want to be able to use a php script to open and read Emails on a particular account. I am not picky about which or what kind of interface. I have been trying IMAP as it is the only one that I have found.

//$hostname   = '{mail.mysite.com:110}INBOX'; //array(1) { [0]=> string(49) "[CLOSED] IMAP connection broken (server response)" }
//$hostname   = '{mail.mysite.com:110/pop3}INBOX'; //array(1) { [0]=> string(142) "Certificate failure for mail.mysite.com: Server name does not match certificate: /OU=Domain Control Validated/CN=*.websitesource.net" }
$hostname   = "{mail.mysite.com:110/pop3/novalidate-cert}INBOX"; //array(1) { [0]=> string(12) "syntax error" }
//$hostname   = '{mail.websitesource.net:110/pop3}INBOX'; //array(1) { [0]=> string(12) "syntax error" }

//A temp account for testing
$user       = '[email protected]';
$password       = '12345678!';

/* try to connect */
$inbox = imap_open($hostname,$username,$password,0,0) or die( var_dump(imap_errors ()) );

 //see errors at top of code, current error 'syntax error'

Solution

  • You are using the wrong variable. Replace $username with $user

    $inbox = imap_open($hostname,$user,$password,0,0) or die( var_dump(imap_errors ()) );