SMTP is an acronym for Simple Mail Transfer Protocol, and an SMTP server is a machine that transports mail, just like a web server is a machine that displays web pages when requested. An SMTP server is sometimes referred to as an outgoing mail server, which brings me to the point—you need such a server in order to complete the exercises in this chapter. On Linux/Unix, Send mail and Qmail are popular packages. On Windows, the SMTP service in the Windows NT Service Pack, or the service built into the Windows 2000 operating system, is often used.
However, if you have installed Apache, PHP, and MySQL as part of a development environment on your personal machine, you probably do not have SMTP running locally. If that's the case, you can access an outgoing mail server that might already be available to you.
| Note |
If you skipped the first three chapters of this book and are using PHP as part of an Internet service provider's virtual hosting package, the SMTP server should already be installed on that machine, and PHP should be properly configured to access it. |
If your machine is connected to the Internet via a dial-up connection, DSL, cable, or other type of access, you can use your Internet service provider's outgoing mail server. For example, if your development machine is a Windows box with a DSL connection to the Internet, you can use something like mail.yourprovider.com as your outgoing mail server. The rule of thumb is that whatever you have configured within your e-mail client (Eudora, Outlook, Netscape Mail, and so on) as your outgoing mail server will also function within your PHP code as your SMTP server. The trick is making PHP aware of this little fact, which you learn about next.
In the php.ini master configuration file, there are a few directives that need to be set up so that the mail() function works properly. Open php.ini with a text editor and look for these lines:
[mail function]; For Win32 only. SMTP = localhost ; For Win32 only. sendmail_from = me@localhost.com ; For Unix only. You may supply arguments as well (default: 'sendmail -t -i'). ;sendmail_path =
If you are using Windows, you'll need to modify the first two directives, SMTP and sendmail_from. If you plan to use the outgoing mail server of your ISP (in this example, suppose it's called DSLProvider.net), the entry in php.ini would look like this:
SMTP = mail.dslprovider.net
The second configuration directive is sendmail_from, and this is the e-mail address used in the From header of the outgoing e-mail. It can be overwritten in the mail script itself but normally operates as the default value. For example:
sendmail_from = youraddress@yourdomain.com
Of course, replace <youraddress@yourdomain.com> with your own address.
If you're on Linux or a Unix variant, sendmail_path is all you need to worry about, and it should look something like this:
sendmail_path = /usr/sbin/sendmail
Or, if you're using Qmail
sendmail_path = /var/qmail/bin/sendmail
In the sendmail_path directive, you can also set configuration flags to specify queuing options or to explicitly set the Return-Path header, such as
sendmail_path = /usr/sbin/sendmail -t -fyou@yourdomain.com
After making changes to the php.ini file, restart the web server and use the phpinfo() function to verify that the changes have been made. When that's done, you're ready to send some e-mail using PHP.