Automatically set SMTP port depending on mail encryption type.
This only occurs if the SMTP port field is using a standard port (25, 465, 587). Custom ports are not overwritten. Fixes https://github.com/octobercms/october/issues/4755
This commit is contained in:
parent
acd0616aaa
commit
ce8c96b66f
|
|
@ -145,4 +145,32 @@ class MailSetting extends Model
|
|||
'ssl' => 'system::lang.mail.smtp_encryption_ssl',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter fields callback.
|
||||
*
|
||||
* We use this to automatically set the SMTP port to the encryption type's corresponding port, if it was originally
|
||||
* using a default port.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param string|null $context
|
||||
* @return void
|
||||
*/
|
||||
public function filterFields($fields, $context = null)
|
||||
{
|
||||
if (in_array($fields->smtp_port->value ?? 25, [25, 465, 587])) {
|
||||
switch ($fields->smtp_encryption->value ?? '') {
|
||||
case '':
|
||||
default:
|
||||
$fields->smtp_port->value = 25;
|
||||
break;
|
||||
case 'tls':
|
||||
$fields->smtp_port->value = 587;
|
||||
break;
|
||||
case 'ssl':
|
||||
$fields->smtp_port->value = 465;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ tabs:
|
|||
label: system::lang.mail.smtp_port
|
||||
tab: system::lang.mail.general
|
||||
span: auto
|
||||
dependsOn: smtp_encryption
|
||||
trigger:
|
||||
action: show
|
||||
field: send_mode
|
||||
|
|
|
|||
Loading…
Reference in New Issue