I am Hack Sparrow
Captain of the Internets.

Solution to PHP imap_open Invalid Certificate Failure (Self-signed certificate or untrusted authority)

PHP Notice: Unknown: Certificate failure for mail.domain.com: Self-signed certificate or untrusted authority:When you try to do this:

$mbox = imap_open('{mail.domain.com}INBOX', 'user@domain.com', 'userpass');
You get this warning:Warning: imap_open() [function.imap-open]: Couldn't open stream {mail.domain.com:143}INBOX in E:\Projects\mailer\main.php on line 4Notice: Unknown: Certificate failure for mail.domain.com: Self-signed certificate or untrusted authority: C=US, S=NY, L=New York, O=Courier Mail Server, OU=Automatically-generated IMAP SSL key, CN=localhost, E=postmaster@example.com (errflg=2) in Unknown on line 0To fix it, you need to send an additional flag in the imap_open query saying you don't care if the certificate is valid or not.
$mbox = imap_open('{mail.domain.com:143/novalidate-cert}INBOX', 'user@domain.com', 'userpass');
The novalidate-cert fixes it.Notes
  • php_imap extension should be enabled for imap_open to work.
  • imap_open may not work on shared hosts.
  • IMAP username is the email address.
Excercise
  • What does imap_reopen() do?
  • Why might imap_open not work on shared hosts?
  • What are the uses of other imap_open flags?
References
  1. PHP imap_open()
  2. PHP imap_reopen()
  3. IMAP Protocol

10 Responses to “Solution to PHP imap_open Invalid Certificate Failure (Self-signed certificate or untrusted authority)”

  1. Ezequiel says:

    Excelent!

  2. brain says:

    thanks!

  3. Mingyang Gao says:

    thanks a billion!

  4. Captain says:

    Most welcome, Mingyang.

  5. Mohammad Mostafa Shahreki says:

    Thanks a lot, worked perfect.

  6. Alex says:

    Excelent! Brother.

  7. Sergio says:

    More more Thanks….!!!

  8. bonga says:

    Thanks a lot man worked..!!!!! after 2hours of struggling

  9. Nadeem Ahmed says:

    Thanks a lot man its worked .

  10. Hugo says:

    Gracias!!!!!

Make a Comment