-1

Is there anyway to improve a PHP mail() call like the following to lower the risk of having it being classified as spam by providers like Gmail?

$to      = "alice@somewhere.com";
$subject = "One Last Step to Get Started";
$message = "To get going with your account on example.com, just click the link below. Thanks for signing up!\r\n\r\nhttp://example.com/?echeck=$id\r\n\r\n\r\n\r\n\r\nDidn't sign up for example.com? Probably someone typed in your address by mistake. If you want, you can tell us but there's no need.\r\n\r\n\r\n\r\nBest,\r\nThe team";
$headers = 'From: alerts@example.com' . "\r\n" .
   'Reply-To: contact@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
mail($to, $subject, $message, $headers);

Right now, services such as Gmail usually mark this as spam and mail-tester.com gave it a score of 3.6/10, for the most part because the DKIM record wasn't valid (I have no idea where mail() is getting the record it's using).

If it's not possible to improve a mail() request, is there a better way to send email from a PHP website without using an outside service? I already have Exim4 installed on my server, so is it possible to use that? I want an easily customization and expandable solution with a limited amount of code, something similar to mail() but with more features.

Laef
  • 1,086
  • 2
  • 11
  • 27

1 Answers1

0

You can use services like Mailgun. It provides an API for sending an email. It has a library for PHP.

Shubhamoy
  • 3,718
  • 2
  • 19
  • 24