Can I send emails using the php mail function with SendGrid smtp relay? [closed]

I have been trying to send emails from my app using the PHP mail function. I am currently hosted at DigitalOcean and the only way for me to send out emails is with services like SendGrid.

I have done everything according to their integration guide, but I still do not know how it works.

Can I send emails using the PHP mail() function?

Here is what I have done so far ...

  1. Update the CNAME records to match those of SendGrid.
  2. Verify that the records have been set.
  3. I have authenticated my domain.
  4. I have sent an email using Outlook.

I can send out emails with my Outlook but I cannot send out emails from my app. I really don't understand how this works?

Are there any records I need to update before I can send out emails? Do I have to use SendGrid API to send out emails or can I simply use PHP mail() function?

By the way, I have cPanel installed on my server and it handles my emails outgoing, and incoming


The php mail() function on Linux and similar Unix like system uses the system sendmail command as the mail interface.

For that sendmail command to use Sendgrid (or another service) means that your system SMTP service needs to be configured to do so. Typical smtp servers are for example postfix, exim and the venerable sendmail itself. That may not be the best solution when your server hosts email domains.

Alternatively install ssmtp which is much easier to configure than conventional fully fledged smtp servers and adjust the sendmail_path in your php.ini configuration file to use ssmtp