286
Send E-mail with PHP ............................................
2 In your editor, open a new
PHP document.
3 Type <?php.
4 Type mail(“?”, $
POST[‘?’], $
POST[‘?’]);, replacing
the first? with your e-mail
address, the second with the
name of the subject field
from the HTML form, and the
third with the name of the
message field from the form.
5 Type ?>.
6 Type
Your email
message has been
sent.
The e-mail capability is
added to the form.
1 In your editor, open or create
an HTML form that contains
fields for a user to enter a
subject and message.
Send E-mail with PHP
A
very common request from bosses and clients alike is the ability to have the data entered into a
form e-mailed to a given address. Fortunately, PHP makes this very easy through the use of its
mail() function. The function takes three arguments: the first is the address to which the e-mail
should be sent; the second, the subject of the e-mail; and the third, the message itself. Any or all
of these arguments can be variables from an HTML form. Pages that send e-mail should also have
additional code to display some sort of confirmation message to the user.