Chapter 37. Sending E-Mail with PHP
This chapter is all about using PHP (and, in some cases, databases) to send e-mail. If you're looking to receive e-mail with PHP, by using a protocol such as POP3 or IMAP, please refer to the PHP manual for those functions.
Sending E-Mail with PHP
Sending mail is where PHP really comes into its own. But before you can send any mail from your server, you need to tweak the configuration file a little.
Windows configuration
In Windows, you need to set two variables in the php.ini file:
SMTP: A string containing the DNS name or IP address of an SMTP server that relays for the Windows machine on which PHP is installed. If it is on the PHP server, specifylocalhost.sendmail_from: A string containing the e-mail address of your default PHP mail sender (for example, mailbot@example.com).Tip
IIS4+ has an SMTP server built in, which is lighter than Exchange Server, if you don't need the power of the latter.
Linux configuration
You need to check and possibly change one variable in the php.ini file if you're using Unix: sendmail_path, a string containing the full path to your sendmail program (usually /usr/sbin/sendmail or /usr/lib/sendmail), a replacement, or a wrapper (such as /var/qmail/bin/sendmail).
The mail function
The mail() function is the primary function used to send mail with PHP. This function, which returns a Boolean, attempts to send one message using the data within the parentheses. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access