-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.

4

1 回答 1

0

您可以使用Mailgun等服务。它提供了一个用于发送电子邮件的 API。它有一个 PHP 库。

于 2016-06-05T18:23:07.527 回答