Framadate crashed on poll creation when PHPMailer send mail to localhost server which is no TLS
Context
- Framadate 1.1.7
- PHPMail 6.0.5
- local SMTP Server with NO TLS on Debian Stretch
- config.php :
- 'use_smtp' => true,
- 'smtp_options' => [
- 'host' => 'localhost',
- 'auth' => false,
- 'username' => '',
- 'password' => '',
- 'secure' => false,
- 'port' => 25,
Problem
On last step of poll creation, Framadate crashed (empty page in browser) when sending mails.
Apache logs:
PHP Fatal error: Uncaught PHPMailer\\PHPMailer\\Exception: SMTP Error: Could not connect to SMTP host. in /var/www/date.chapril.org/vendor/phpmailer/phpmailer/src/PHPMailer.php:1900
Stack trace:
#0 /var/www/date.chapril.org/vendor/phpmailer/phpmailer/src/PHPMailer.php(1725): PHPMailer\\PHPMailer\\PHPMailer->smtpConnect(Array)
#1 /var/www/date.chapril.org/vendor/phpmailer/phpmailer/src/PHPMailer.php(1481): PHPMailer\\PHPMailer\\PHPMailer->smtpSend('Date: Sun, 29 J...', 'This is a multi...')
#2 /var/www/date.chapril.org/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320): PHPMailer\\PHPMailer\\PHPMailer->postSend()
#3 /var/www/date.chapril.org/app/classes/Framadate/Services/MailService.php(58): PHPMailer\\PHPMailer\\PHPMailer->send()
#4 /var/www/date.chapril.org/create_date_poll.php(226): Framadate\\Services\\MailService->send('cmomon@april.or...', '[date.chapril][...', 'Ce message ne d...')
#5 {main}
th
Syslog:
Jul 29 15:30:07 lamp postfix/smtpd[32461]: connect from localhost[127.0.0.1]
Jul 29 15:30:07 lamp postfix/smtpd[32461]: lost connection after STARTTLS from localhost[127.0.0.1]
Jul 29 15:30:07 lamp postfix/smtpd[32461]: disconnect from localhost[127.0.0.1] ehlo=1 starttls=1 commands=2
The problem seems to come from PHPMailer configuration.
Watching PHPMailer.php file at line 270:
/**
* Whether to enable TLS encryption automatically if a server supports it,
* even if `SMTPSecure` is not set to 'tls'.
* Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
*
* @var bool
*/
public $SMTPAutoTLS = true;
Watching PHPMailer.php file at line 1898:
//Automatically enable TLS encryption if:
// * it's not disabled
// * we have openssl extension
// * we are not already using SSL
// * the server offers STARTTLS
if ($this->SMTPAutoTLS and $sslext and 'ssl' != $secure and $this->smtp->getServerExt('STARTTLS')) {
$tls = true;
}
if ($tls) {
if (!$this->smtp->startTLS()) {
throw new Exception($this->lang('connect_host'));
}
// We must resend EHLO after TLS negotiation
$this->smtp->hello($hello);
}
So, the PHPMailer comments say that TLS is used if available, and so we hope/wait that it will work without TLS if it is not available. But the source code throws an exception if the TLS try failed. There is no alternative: TLS or throw. Why force TLS?
Is-it a PHPMailer bug???
The consequence is: Framadate + SMTP localhost server + NO TLS => FAILED.
Suggestions
First, open an issue on the PHPMailer project.
Second, add an option parameter in config.php file to make possible to set the $mail->SMTPAutoTLS = false
in MailService.php file.
Currently, I have to modify the Framadate MailService.php file to force SMTPAutoTLS to false:
private function configureMailer(PHPMailer $mailer) {
$mailer->isSMTP();
$mailer->SMTPAutoTLS = false; // <-- Temporary fix from Cpm 2018-07-29