Dennis VW
Dennis VW

Reputation: 3197

Why doesn't php's imap_open() like SSL?

Might not be a very helpful question, but I can't image there isn't a clear answer to this problem. I just figured out via some already answered questions about imap_open() connection problems, that when connecting to an SSL server the function will most likely return an error. So I was just wondering, what the problem is for PHP to use SSL?

Using this connection string returns error:

function connect($host, $port, $login, $pass){

    $this->server = $host;
    $this->username = $login;

    $this->link = imap_open("{". $host .":". $port."}INBOX", $login, $pass);
        if($this->link) {
            $this->status = 'Connected';
    } else {
        $this->error[] = imap_last_error();
        $this->status = 'Not connected';
    }
}

While this one connects without issues:

function connect($host, $port, $login, $pass){

    $this->server = $host;
    $this->username = $login;

    $this->link = imap_open("{". $host .":". $port."/imap/ssl/novalidate-cert}INBOX", $login, $pass);
        if($this->link) {
            $this->status = 'Connected';
    } else {
        $this->error[] = imap_last_error();
        $this->status = 'Not connected';
    }
}

Upvotes: 1

Views: 2535

Answers (1)

Capilé
Capilé

Reputation: 2088

If the server requires an encrypted connection, it means you are connecting to an encrypted port, and your script will fail if you don't use /ssl (won't connect at all).

The server may also accept a plaintext connection and then require encryption (see STARTTLS), but I guess it would connect and then send a IMAP error.

This can be checked by the port you are connecting and your mail server specification. Usually ports 465/993 are assigned to use encrypted TLS/SSL connections, while 25/143/587 may accept an unencrypted connection and then ask for an upgrade.

Upvotes: 2

Related Questions