skip to Main Content

Background context: New mailserver using php8.1, Ubuntu 22.04. Old server php7.4, Debian Stretch both using Phpmailer 5.5.

Previous server would send emails with an attachment and place a copy including attachment in sent folder. New server sends properly, but will not save a copy (to sent folder).

The error message is:
TLS/SSL failure for [server name]: SSL negotiation failed (errflg=2) in Unknown on line 0

I can not find any detail of what this error is in the mail.log

This is the code I have used successfully before, extended class (but with temporary debug lines to verify the data being passed to imap_append):

$imapStream = imap_open("{" . $this->Host . "}" . $path , $this->Username, $this->Password);

        echo "nHost: ".$this->Host."n";
        echo "npath: ".$path."n";
        echo "nUsername: ".$this->Username."n";
        echo "nPassword: ".$this->Password."n";
        echo "nimapStream: ".$imapStream."n";

        imap_append($imapStream, "{" . $this->Host . "}" . $path, $message);
        imap_close($imapStream);

Thunderbird and Dovecot both work perfectly, it is literally just PHPMailer with the problem. The PHP IMAP extension is installed.

I have tried upgrading Phpmailer for a newer version -6.9.1, but that has brought a raft of other issues.

This is obviously an IMAP auth issue, but I have no idea where to get information to troubleshoot it.

Any help would be much appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Just in case anybody has a similar problem, here is a good reference: https://www.macs.hw.ac.uk/~hwloidl/docs/PHP/function.imap-open.html

    Indeed, this isn't a Phpmailer issue. The code is part of my own Accounting package that I created about 5 years ago, so that I can raise invoices from my mobile phone. I forgot that it's an add-on of my own, it was just logical to extend the php class and do the 'filing' after Phpmailer sent the email. So credit to Synchro for responding when it's not really his area. Thank you.

    $imapStream = imap_open("{" . $this->Host . "/imap/ssl}" . $path , $this->Username, $this->Password);

    This is the fix which I figured out from the above resource. Explicit imap/ssl. Very important in modern email communication.


  2. PHPMailer really don’t get involved in this – it’s just subject to the environment it runs in, requiring both IMAP and openssl PHP extensions for it to work. The error you have shown suggests that PHP can’t make or verify a secure IMAP connection. This could be due to a misconfiguration in your mail server (e.g. if it’s serving an invalid or untrusted certificate, or the port you’re connecting to doesn’t support encryption – check your port number), or in PHP itself (e.g. your CA bundle is outdated, or you have an outdated openssl extension).

    I suggest checking the IMAP connection using openssl on a command line from your server, for example:

    openssl s_client -connect map.example.com:993 -crlf
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search