0

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

2 Answers 2

1

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

1
  • Thank you for helping. I am a PHP programmer but have no experience with SMTP or SSMTP. I am using cPanel as management software for my server. I think that they have exim. What records do I need for this to work? Oct 16, 2021 at 4:49
0

It's always best to send email using PHP with cURL or the SMTPAPI Header, as per documentation provided in SendGrid Manual.

URL: SendGrid PHP Code Example

So it will always hit recipient's inbox.

Not the answer you're looking for? Browse other questions tagged .