I can send emails to myself and other people on my mail server using PEAR Mail. But when I try to send to another server, I get an error:
Relay access denied.
I've checked the SMTP configs and they're exactly the same as in my email client.
What could it be?
Relay access denied.
A "relay" is a mail server that acts as an open gateway, allowing anyone to connect to it and send mail through it ... to anyone. If the target isn't local, a relay will make a best effort to pass it on.
Obviously this is a tremendously bad idea.
Chances are that the mail server you are using is either locked down to local delivery only, or it wants you to authenticate first to prove that you are permitted to send mail through it.
You will need to contact your sysadmin to ask him or her about the error, and exactly what you need to do in order to send mail through it.
Is your email client authenticating to your SMTP server? Most servers will allow authorized/authenticated users to relay mail through them. That way you can be (say) a salesman in a hotel room somewhere and still send mail to a 3rd party via your corporate mail server.
Check that your PHP mail call is using the proper SMTP credentials (which means username/password, not just the server address). Since your email client can relay, but your script can't, most likely the script isn't authenticating.