Practice 7

Main | Review of Operators | Mathematical Functions | Practice 5 | Solution 5 | HTML Forms | PHP Forms | Practice 6 | Solution 6 | PHP and E-mail | Practice 7 | Solution 7

For our next practice you will make an online e-mail application, from which users may e-mail you from any web browser. You may interact with this application (and send me an email) by clicking here. After some experimentation, you might notice that you will get error messages if you leave either the message or e-mail address field blank. You will implement the PHP that produces some of this behavior and use the mail() function to make a version of this application of your own, which will e-mail you.

This practice will build on Practice 6. It will borrow its structure in that it will use a function to display an HTML form at the appropriate times. It will also use empty() and isset() to display the form or send email when appropriate. The actual PHP code for this application is about 55 lines long, but to complete this exercise you only need to write 3 lines of PHP.

To complete this exercise you must:

  • Create a file in "public_html/php" called "mail.php".
  • Be sure that "mail.php" is viewable from the web.
  • Fill in "mail.php" with this incomplete code.
  • Complete the PHP section of the incomplete code so that it satisfies the following:
    1. Use empty() to see if the user left the $subject variable empty and set it to a default value.
    2. Call mail() so that the message will be sent to your address.
    3. Set the output of mail() equal to a true or false variable to echo a message to the user as to whether the mail has been sent or not.
NOTE: The numbers above (1-3) will correspond to a number in the code you must complete. Use these numbers to guide you so that you know where to edit the code.


jfulton [at] member.fsf.org
22 Aug 2013