Mail uses a very old protocol from the early days, before security was a major deal. Mailservers were generally happy to forward on mail from anyone to anyone. Rather than being seen as a security issue, this was seen as a way of adding redundancy onto the syste, If your usual mailserver was in a bad state, you could just hitch a lift on another one.
You just contacted any mail server and asked it something like "Hey, can you send on a mail for me. From John@catsarebetterthandogs.com to Mary@nowaydogsrule.com, and the message is "Yay cats!".
Of course things have tightened up somewhat now, but mst mailservers are still configured to allow anyone on their domain to send mail through them. So when you try to send mail from a PHP script, it is the user which is running the PHP script (nobody, apache, or someone like that) who is actually contacting the mail server on yur behalf, and they have the right to send mail. This is up to your sysadmin though, and could change.