Wednesday, September 8, 2010

PHP Mail

• PHP Mail Introduction: One of the major uses of a server side scripting language is to provide a way of sending e-mail from the server and, in particular, to take form input and output it to an e-mail address. The mail() function allows you to send emails directly from a script.

• Requirements: For the mail functions to be available, PHP requires an installed and working email system i.e SMTP server that PHP can connect to.

Knowing SMTP server: SMTP is the acronym for Simple Mail Transfer Protocol, and an SMTP server is the machine that runs this protocol and sends out the mail. Running the protocol essentially means running a program such as Sendmail or Qmail if you're on a non-Windows machine. On Windows, the SMTP Service that is part of the Windows NT Service Pack or built in to the Windows 2000 operating system is typically the one running.

• "How can a server be available if it's not currently being run?" you might ask. Well, if that machine is connected to the Internet via a dial-up connection (or DSL or cable), you can use your ISP's outgoing mail server. For example, if your development machine is a Windows 98 box with a 56Kbps modem connected to the Internet via EarthLink, then you can use mail.earthlink.net as your SMTP server. Whatever e-mail client you use (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.

• The program to be used is defined by the configuration settings in the php.ini file.

Installation: The mail functions are part of the PHP core. There is no installation needed to use these functions.

• Runtime Configuration: The behavior of the mail functions is affected by settings in the php.ini file. In the php.ini master configuration file located in wamp icon, there are a few directives that need to be set up so that the mail() function works properly.

The options you want to check are:

• SMTP

• sendmail_from

• sendmail_path