0

I'm trying to fetching email from particular email account. Code is working fine when i'm passing correct details in the imap_open(); function. But i want to add validation, when someone pass incorrect email address or password then it should return error. I followed the instruction of this up-voted answer but it doesn't work.

$mbox = imap_open("{mail.example.com.com:143/novalidate-cert}", "dev@example.com", "wrongPassWord");
// Check if imap connect or not
if($mbox){
    echo 'connect';
}else{
    echo 'Not connect';
}
imap_close($mbox);

Also when i add wrong detail then it returning warning errors.

enter image description here

Can anyone guide me regarding this how can i check if imap_open() connect or not and prevent the warning errors, that i can fix this issue. I would like to appreciate if someone guide me. Thank You.

Community
  • 1
  • 1
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68

1 Answers1

0

imap_open generates E_WARNING on error. You can suppress it for whole application using error_reporting() or by adding @ before imap_open() call. Then your example will work.

$resource = @imap_open(...);

Also, is much better to use higher level library then low-level functions. I like this one: https://github.com/ddeboer/imap

Tomáš Jacík
  • 645
  • 4
  • 12