I can send email from tinker but when I try to send email from code in laravel framework I get below error:
Swift_TransportException (550)
Expected response code 250 but got code "550", with message "550 Bad HELO - Host impersonating domain name [mydomain.com] "
This is my simple mail method to test sending email from laravel controller :
Mail::send('errors.401', [], function ($message) { $message->to('my.email@gmail.com')->subject('this works!'); });
.env file:
MAIL_DRIVER=smtp
MAIL_HOST=mail.mydomain.com
MAIL_PORT=587
MAIL_USERNAME=info@mydomain.com
MAIL_PASSWORD=<password>
MAIL_ENCRYPTION=
I've done below steps but still it doesn't work:
composer dump-autoload
php artisan view:clear
php artisan cache:clear
php artisan config:cache
Update:
My code is on an ubuntu server which I configured dns server and bind9 to connect domain to server and I have an external mail server to handle emails.
So whenever an email request is created in ubuntu server, it'll forward it to external mail server.
where should I look for problem?
I've Fixed the problem after wasting lots of time, hope this answer stop wasting others time.
it was due to local domain name, we need to define a local name in our mail.php config file which makes our server not to confuse with external server domain name.
'local_domain' => env('MAIL_HOST', 'mail.mydomain.com'),