PHP's ability to send e-mail is so heralded that developers often tout this particular feature as a symbol of the language's practicality. In fact, to send an e-mail from a PHP-powered web site, all you need to do is call the native
mail() function like this:
mail("firstname.lastname@example.org", "Welcome to the Website", "Thank you for registering!");
If you execute this code on any PHP-enabled server running Sendmail, the owner of the address
email@example.com should soon receive a message with the subject
Welcome to the Website and the message body
Thank you for registering!.
No matter what type of web site you're building these days, chances are you'll need to create an automated mechanism for sending e-mail to various parties. The applications for this type of mechanism really are countless. Consider these common functions:
- Sending a visitor's contact form query to the appropriate staff member's inbox
- Forwarding a post-purchase order receipt to a customer's e-mail address
- Providing a forgetful user with a password recovery link
- Asking a newly registered user to confirm his e-mail address
The most commonplace way to send these e-mails is through the server-side language you're using to power the web site, and perhaps the easiest language to use in this regards is PHP.
Two aspects of sending e-mail with PHP commonly confuse people:
mail()function doesn't work by default on the Windows platform.
mail()function is not intended for sending large quantities of e-mail.
Find out how to handle these issues and learn everything else you need to know about sending e-mail with PHP by reading Jason Gilmore's entire Web Developer's Virtual Library tutorial.