Occasionally I have had trouble sending emails using the builtin mail() function in PHP. Sometimes emails never reached their intended destination. Naturally I have assumed that there might be a problem with some spam filters used. However, lazy as I am, I have not given it a second thought. Instead I have used a PHP class that allows me to send emails using a remote smtp server using an account on that server. This has been a good solution for my setup anyways. A few days ago a friend of mine was asked to investigate the very same problem for a client.

The problem seems to be that PHP use the ini directive sendmail_from to set the from email address in the SMTP protocol. If this is not correctly set, or if it does not match the from header in the email headers, the email is caught by spam protection software.

The simplest solution is to set the directive during execution:

ini_set("sendmail_from", $email_from);

$headers = "From: $email_from";

mail($to, $subject, $message, $headers);

The problem as well as the solution was already known by others. The operating system this time was windows and I know there are differences in the implementation between the windows and linux version of mail(). I am not sure if the problem exist on both platforms.

Still I bet there are lots of people out there with this problem without them knowing it. It could be a good idea to include more detailed information about this ini entry and its implications in the actual mail() documentation. Sending emails from web pages is, to say the least, a very common task.

There are a lot of things email providers may check to see if a mail is spam or not, but generally, they have nothing to do with the OS the mail was sent from.

commented: I second this +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.