Why does PHP mail() require a mail program like sendmail/postfix/etc. for sending emails?
Why does the PHP mail()
function require a mail program like sendmail/pos开发者_StackOverflow社区tfix/etc. for sending emails?
I ask because sending email is a client action and not something that needs to run a server.
What is so complicated about creating a native PHP mail function without the need to install a sendmail/postfix/etc. program that has excessive functionality as a server that can get requests and not just send email as a client?
Most likely: sendmail
existed before PHP's mail()
, so in the true spirit of *nix:
Why re-create functionality when it already exists on the CLI?
The reason you want to hand the mail off to something else is that Mail is a complicated beast that is best deferred to something better designed to handle that.
A simple case is when you mail something to a server that is offline. It's "OK" for a mail server to go offline, there's built in logic to retry message sends in the operations of the mail servers. But if you simply open up an SMTP socket and start barking protocol, and it fails, then you've lost that queueing capability that you get "for free" with the mail servers.
Mail is just one of those things best delegated to those ancient systems that have all of the lore and details coded in to them over years of painful interoperability testing and implementation.
PHP doesn't send mail itself, but delegates to another program to send mail for it.
You can get around this restriction by using the PEAR Mail package instead, which has SMTP support.
The reason is because the mail()
function is not an MTA, only a "encoder" for the actual MTA.
Why not? I believe it would be unpractical to implement a decent and secure MTA setup with PHP alone.
EDIT: What exactly does an MTA do?
When a mail server forwards (routes) email to another server, it acts like a client and uses SMTP to forward the email. The client part is called an Mail Delivery Agent (MDA) and is often a distinct piece of software.
This part of the sendmail tutorial is helpful.
It's called "sendmail" for a reason. Networks' used it for decades for inter-communication. Whether you know it or not, that IS how mail gets sent. -- By a program confined to an RFC protocol and designed to format, package and deliver data to ... other servers. It can run as a daemon sitting on a port or from an instance invoked at the cmdline. It's a simple tool, and an efficient one.
-Gama Xul (*nix guy)
Trying to send mail with something other than a mail-sending-program (like a web-browser client or a PHP language mod) would be like trying to cut something with a gun. There's a lot more going on there and too many conflicting conditions could hang it up. It just wasn't designed for it and wouldn't function efficiently.
精彩评论