Mail: Set domain for EHLO based upon the APP_URL

For #5990
This commit is contained in:
Dan Brown
2026-02-28 18:46:05 +00:00
parent 10c46534e0
commit ec3dd856db
2 changed files with 28 additions and 0 deletions

View File

@@ -65,6 +65,13 @@ class AppServiceProvider extends ServiceProvider
URL::forceScheme($isHttps ? 'https' : 'http');
}
// Set SMTP mail driver to use a local domain matching the app domain,
// which helps avoid defaulting to a 127.0.0.1 domain
if ($appUrl) {
$hostName = parse_url($appUrl, PHP_URL_HOST) ?: null;
config()->set('mail.mailers.smtp.local_domain', $hostName);
}
// Allow longer string lengths after upgrade to utf8mb4
Schema::defaultStringLength(191);

View File

@@ -122,6 +122,27 @@ class ConfigTest extends TestCase
});
}
public function test_app_url_changes_smtp_ehlo_host_on_mailer()
{
$getLocalDomain = function (): string {
/** @var EsmtpTransport $transport */
$transport = Mail::mailer('smtp')->getSymfonyTransport();
return $transport->getLocalDomain();
};
$this->runWithEnv(['APP_URL' => ''], function () use ($getLocalDomain) {
$this->assertEquals('[127.0.0.1]', $getLocalDomain());
});
$this->runWithEnv(['APP_URL' => 'https://example.com/cats/dogs'], function () use ($getLocalDomain) {
$this->assertEquals('example.com', $getLocalDomain());
});
$this->runWithEnv(['APP_URL' => 'http://beans.cat.example.com'], function () use ($getLocalDomain) {
$this->assertEquals('beans.cat.example.com', $getLocalDomain());
});
}
public function test_non_null_mail_encryption_options_enforce_smtp_scheme()
{
$this->checkEnvConfigResult('MAIL_ENCRYPTION', 'tls', 'mail.mailers.smtp.require_tls', true);