mail() generates an error on Windows

The PHP mail() (PHP mail function) can generate an SMTP error on Windows when messages contain the wrong line endings. This article explains the cause and how to fix it.

Error message

The following error indicates the problem:

Warning: mail(): SMTP server response: 451 
See http://pobox.com/~djb/docs/smtplf.html.

This error message indicates that you are sending email from PHP containing single linefeeds (\n) instead of proper email linefeeds (\r\n).

You can read more about the problem here:

How to fix the line endings

You can usually fix this problem by making sure that, before you call the mail() function, you convert every single \n to \r\n:

$ent = str_replace("rr", "r", str_replace("n", "rn", $ent));
Was this article helpful?

Related Articles