Sending Mail with SMTP and PHP

Outgoing email is sent using the Simple Mail Transfer Protocol (SMTP). Fortunately, PHP’s built-in mail() function handles all SMTP socket-level protocols and handshaking for you. The mail() function acts as your mail client, sending email messages just as Outlook or Thunderbird might.

Configuring PHP to Send Mail

Before you can use PHP as a mail client, you must edit PHP’s configuration file, php.ini, to point PHP to the mail server’s location. For example, the script in Example 15-1 shows the section of php.ini that configures PHP to work with sendmail, the Unix mail server on many networks.

Example 15-1. Configuring PHP’s mail() function

[mail function] ; For Win32 only. SMTP = localhost ; For Win32 only. ;sendmail_from ...

Get Webbots, Spiders, and Screen Scrapers, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.