1

I configured my mail server as in the following guide: https://www.digitalocean.com/community/tutorials/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassasin Now I am trying to send mails via PHP using this library: https://github.com/PHPMailer/PHPMailer

But the problem seems the SSL (cert). I am not sure if the script is not able to establish a connection or if the problem is the unverified SSL cert. Do you guys have any idea? Should I use startssl oder starttsl in the script?

SSLaccept error from x.com[x.x.x.x]: 0
Dec 8 17:45:23 x postfix/submission/smtpd[13479]: warning: TLS library problem: 13479:error:14094418:SSL routines:SSL3READBYTES:tlsv1 alert unknown ca:s3pkt.c:1258:SSL alert number 48:

My code so far:

function send_mail($from, $from_name, $to, $to_name, $subject, $content) { require 'PHPMailerAutoload.php';

    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'mail.x.com';                   // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'noreply@x.com';                 // SMTP username
    $mail->Password = 'so secret';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    $mail->From = $from;
    $mail->FromName = $from_name;
    $mail->addAddress($to, $to_name);                     // Add a recipient

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = $subject;
    $mail->Body    = $content;
    $mail->AltBody = 'Please use an html compatible Client to view this mail!';

    if(!$mail->send()) {
        return false;
    } else {
        return true;
    }

}
Cr41s3
  • 97
  • 2
  • 11

1 Answers1

0

I had the same error, and finally figured out that phpmailer wants to use a normal smtp connection and then STARTTLS or STARTSSL to initialize encryption. In other words: it wants to connect to a submission service instead of an smtps service. Submission is on port 587 (usually) and smtps is on port 465. In fact, the smtps protocol was deprecated a long time ago. There are still many ISPs out there using smtps, but apparently they shouldn't.

If your mail provider allows you to use submission (port 586) instead of 465, then change your port number in your config and it will work! If you happen to be the sysadmin on the smtp server, then simply start a submission service, listening on port 587. If your ISP only supports smtps, then probably you are stuck. It seems that phpmailer does not handle SMTPS connections that are encrypted from the beginning. It only support connections that can be switched to encrypted (using STARTTLS).

The difference between the two is also described here:

What is the difference between ports 465 and 587?

UPDATE: before you try sending out any email, please update to the very latest version of phpmailer. Download the latest from github ( https://github.com/PHPMailer/PHPMailer ). Do not try to use any other version! Sometimes a small change in the minor version will decide between a successfully sent email and an "smtp connection error".

Community
  • 1
  • 1
nagylzs
  • 3,954
  • 6
  • 39
  • 70