By default, PHP's mail()
function will deliver mail to the sendmail
program on Linux.
For sendmail to work, you are required to have a properly configured and functioning MTA. For example, postfix is an MTA that is relatively easy to configure.
When configuring your MTA, you can either configure it to send mail directly, as a mail server on the internet, or to relay your mail to another server.
Configuring your own MTA to deliver mail directly is not for the light-hearted. Sending email has become complicated now, requiring a lot of work to be able to have your mail accepted by major mail servers like gmail or yahoo.
If your ISP provides an outgoing mail server and is happy to relay mail for you, you can set up postfix to relay all mail via that server instead, and save yourself some configuration hassle. If you use postfix, this simply requires setting it up like the example under Postfix on a null client in the postfix configuration.
The main thing to remember, no matter how you are configuring your mail server, is to avoid setting it up to relay incoming mail on the outgoing network (ie, setting it up as an open relay). In the null mailer example configuration, the line inet_interfaces = loopback-only
achieves this.
Note that an alternative to setting up postfix or something as an MTA is to uses PHP's own built in SMTP support, which essentially means you are using PHP itself as an MTA which only forwards mail to a relay.
The advantage to using a dedicated MTA like postfix is reliability. Postfix can queue email if there is a temporary problem reaching the external mail relay. It also returns as soon as the mail has been queued, so your PHP mail function will execute much faster and won't need to wait while the mail is delivered to the external mail relay.