PHP Sending Email

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!


string $toThe recipient email address
string $subjectThe subject line
string $messageThe body of the email
string $additional_headersOptional: headers to add to the email
string $additional_parametersOptional: arguments to pass to the configured mail send application in the command line


E-Mail I'm sending through my script never arrives. What should I do?

  • Make sure you have error reporting turned on to see any errors.

  • If you have access to PHP's error log files, check those.

  • Is the mail() command configured properly on your server? (If you are on shared hosting, you can not change anything here.)

  • If E-Mails are just disappearing, start an E-Mail account with a freemail service that has a spam folder (or use a mail account that does no spam filtering at all). This way, you can see whether the E-Mail is not getting sent out, or perhaps sent out but filtered as spam.

  • Did you check the "from:" address you used for possible "returned to sender" mails? You can also set up a separate bounce address for error mails.

The E-Mail I'm sending is getting filtered as spam. What should I do?

  • Does the sender address ("From") belong to a domain that runs on the server you send the E-Mail from? If not, change that.

    Never use sender addresses like Use reply-to if you need replies to arrive at a different address.

  • Is your server on a blacklist? This is a possibility when you're on shared hosting when neighbours behave badly. Most blacklist providers, like Spamhaus, have tools that allow you to look up your server's IP. There's also third party tools like MX Toolbox.

  • Some installations of PHP require setting a fifth parameter to mail() to add a sender address. See whether this might be the case for you.

  • If all else fails, consider using email-as-a-service such as Mailgun, SparkPost, Amazon SES, Mailjet, SendinBlue or SendGrid—to name a few—instead. They all have APIs that can be called using PHP.

Got any PHP Question?