I've hit the same problem - except in my case my mail server is complaining about bogus HELO name used: [127.0.0.1] - which seems to be a swiftmailer default.
I cannot figure out how to call setLocalDomain() from Mail::class?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I have been fighting lately with sending emails via SMTP using Mail. Situation as follows: I have been using one server as mail server and second server for website and Laravel sending emails. SPF and DKIM valid, encryption valid, password valid, host valid.
All was working form localhost, but did not work on regular mail server. Error message was "550 Bad HELO - Host impersonating domain name" and in message was of course mentioned website/Laravel domain.
Hours of debugging led me to Swiftmailer file located in lib/dependency_maps/transport_deps.php sets 'transport.localdomain' to $_SERVER['SERVER_NAME'] - and that's the reason why email server thinks I am impersonating. This is default value.
Swiftmailer Swift_DependencyContainer class allows to override this values, changing HELO/EHLO message. This approach is used in Symfony; example code is as follows:
$this->get('swiftmailer.transport')->setLocalDomain('your.mail.domain');
I haven't noticed similar ability of Mail class in Laravel. I think it would be nice feature to have.
If someone is having similar trouble, there is workaround possible by using $_SERVER; not very elegant, but working (must be adedd before sending email).
$_SERVER['SERVER_NAME'] = 'your.mail.domain';
If there is such functionality in Laravel, it would be nice to add this into documentation.
Best regards, Lukasz
Please or to participate in this conversation.