PHP – Why Does PHP Allow Sending Mail from Any Address?

emailPHP

I'm sorry if this has been asked but I'm not quite sure how to search for it. I'm having a bit of trouble understanding how mail() works in PHP. The way I see it, using that function, I can send e-mails from any user on my mail server – existent or not, without needing any credentials or anything. I doubt the guys from PHP would let this be the way I think it is and I also suspect that this has something to do with the fact that e-mails I send from my mail server go straight into the spam folders on other mailing services (gmail, yahoo etc.)

Can somebody shed some light on me and fill the missing link. Thanks!

Best Answer

Unfortunately, this is just how email works. There is no way for PHP to validate whether you are allowed to send mail from a particular address, so it will let you specify any address you want. Your mail server may be configured to reject email from invalid mailboxes, or if you do not have the correct authentication details for a valid mailbox, but most servers are not set up to do this.

As to why your email is being rejected by the large service providers, the most likely cause is that either you are on a blacklist somewhere, you're sending email directly from an end-user ip address without using a relay server, or have not correctly implemented sender address verification for your domain.

Related Topic