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

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

  1. Wilfred says:

    Thanks!

  2. SuperChinazoPoderoso says:

    Thanks, was so useful for me thanks

Make a Comment