0

Recently I moved from HostGator with cPanel to a Digital Ocean droplet.

I still want to use the email service from HostGator.

So in DigitalOcean I added an A record pointing to HostGator IP, and MX record pointing to mail.mydomain.com

I can receive and send emails normally.

When I want to send an email from a Laravel application, unless it uses the same domain of my website, the mail is not sent, for example if I wanted to send to a Gmail account.

I tried with telnet, and in the inbox I saw that gmail rejects the message because it doesn't have a "From header".

Before the migration everything worked correctly so I don't think that I need to add that header to my Laravel email.

Is there something that I am missing in DNS configuration or cPanel?

This is the code that I've been using before the migration and it was working fine, now it sends emails but only when the recipient has the same domain as HostGator, which is my-domain.com:

MAIL_DRIVER=smtp
MAIL_HOST=cloud232.hostgator.com (I tried with mail.my-domain.com and it works too)
MAIL_USERNAME=noreply@my-domain.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=ssl (I tried with tls and port=587 and it works too)
MAIL_FROM_NAME=name
MAIL_PORT=465 (I tried with tls and port=587 and it works too)

Thanks in advance.

Roman
  • 11
  • 3

1 Answers1

1

You can try adding an SPF record to allow the DigitalOcean IP to send emails from your domain.
You can also try sending emails from laravel using the SMTP server of HostGator.In my opinion, using SMTP to send emails from a web application is the most reliable and easiest way to send emails unless you have a third-party email solution.
This is an example code that you can try putting in the mail config file:

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'mail.yourdomain.com'),
'port' => env('MAIL_PORT', 25),
'from' => ['address' => 'yourname@yourdomain.com', 'name' => 'Some Name here'],
'encryption' => env('MAIL_ENCRYPTION', null),
'username' => env('yourname@yourdomain.com'),
'password' => env('yourpassword'),
'sendmail' => '/usr/sbin/sendmail -bs',


Alternatively, you can add these two lines to your .env file:

MAIL_FROM_ADDRESS=yourname@yourdomain.com
MAIL_FROM_NAME="yourname@yourdomain.com"

But This can cause your emails to go to the spam folder due to DKIM failures and other issues. So using SMTP is the best way forward.

Hope This helps.

Shahriar Shojib
  • 322
  • 1
  • 2
  • 11
  • Hi, thank you for your reply. I have that configuration in Laravel, in fact I can send emails using Laravel, so the configuration is right. But when I try a different domain than mine, it fails. – Roman Sep 01 '19 at 10:48