Trouble with Dovecot, Postfix, and PHPMailer

There are many things that can go wrong with a Dovecot/Postfix installation. Here are two things to watch out for:

TLS

The following parameter in /etc/postfix/main.cf will require TLS authentication for everything:

smtpd_tls_auth_only=yes

If you send emails with PHPMailer using SMTP authentication, you will then also need to turn TLS on:

<?php
$mail->SMTPSecure = 'tls';
?>

Alternatively, you can turn off the TLS requirement:

smtpd_tls_auth_only=no

Authentication Mechanism

It seems that when PHPMailer uses SMTP authentication, it cannot use the PLAIN but only the LOGIN mechanism. You need to make sure this is defined in the Dovecot configuration file /etc/dovecot/conf.d/10-auth.conf:

auth_mechanisms = plain login

On my way to finding this out, I had to deal with a lot of error messages such as:

530 Authentication Required
Invalid authentication mechanism
Relay access denied

If you see any of these, you may want to check out the aforementioned INI file settings.