Skip to content

A free, self-hostable news aggregator…

Mailer: allow disabling SMTPAutoTLS via config (#9026)

Gerard Alvear Porras5f94330503c2
diff --git a/config.default.php b/config.default.php
index 800a89bba..66dea4fdb 100644
--- a/config.default.php
+++ b/config.default.php
@@ -211,6 +211,7 @@ return [
'username' => '',
'password' => '',
'secure' => '', // '', 'ssl' or 'tls'
+ 'auto_tls' => true, // maps to PHPMailer’s `SMTPAutoTLS`; set to false to disable opportunistic STARTTLS, e.g. when using a self-signed certificate
'from' => 'root@localhost',
],
diff --git a/docs/en/admins/05_Configuring_email_validation.md b/docs/en/admins/05_Configuring_email_validation.md
index 13753225f..55c16a565 100644
--- a/docs/en/admins/05_Configuring_email_validation.md
+++ b/docs/en/admins/05_Configuring_email_validation.md
@@ -45,6 +45,7 @@ PHPMailer documentation](https://phpmailer.github.io/PHPMailer/classes/PHPMailer
'username' => 'alice', // or maybe [email protected]
'password' => 'yoursecretpassword',
'secure' => 'ssl', // '', 'ssl' or 'tls'
+ 'auto_tls' => true, // set to false to disable opportunistic STARTTLS, e.g. when using a self-signed certificate
'from' => '[email protected]',
],
```
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 968132533..8c178d8bf 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -10,7 +10,8 @@ declare(strict_types=1);
* @property string $environment
* @property array<string,bool> $extensions_enabled
* @property-read string $mailer
- * @property-read array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,'secure':string,'port':int,'from':string} $smtp
+ * @property-read array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,
+ * 'secure':string,'auto_tls':bool,'port':int,'from':string} $smtp
* @property string $title
*/
class Minz_Configuration {
diff --git a/lib/Minz/Mailer.php b/lib/Minz/Mailer.php
index c657bd486..1326afb5f 100644
--- a/lib/Minz/Mailer.php
+++ b/lib/Minz/Mailer.php
@@ -30,7 +30,7 @@ class Minz_Mailer {
protected $view;
private string $mailer;
- /** @var array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,'secure':string,'port':int,'from':string} */
+ /** @var array{'hostname':string,'host':string,'auth':bool,'username':string,'password':string,'secure':string,'auto_tls':bool,'port':int,'from':string} */
private array $smtp_config;
private int $debug_level;
@@ -94,6 +94,7 @@ class Minz_Mailer {
$mail->Username = $this->smtp_config['username'];
$mail->Password = $this->smtp_config['password'];
$mail->SMTPSecure = $this->smtp_config['secure'];
+ $mail->SMTPAutoTLS = $this->smtp_config['auto_tls'];
$mail->Port = $this->smtp_config['port'];
} else {
$mail->isMail();