MMDT1146 PHP Programming
Week 5


Week 5

Email Notes:

  • Sending email is probably the #1 thing php is used for!
  • NEVER put an email address directly into a website anywhere.  Spammers are now harvesting email addresses from websites.
  • Several examples of email scripts will be provided to you in class.
  • If you need a more robust mailer, try PHPMailer.   PHPMailer supports HTML email and authentication.
  • reCaptcha by Google shown in new labs.

In Class Lab 5 (Completed in class)

This lab is to test your knowledge of being able to create a php script that sends a confirmation email to the customer and an email to a corporate email account.

Create a subfolder on your web server named "lab5".  (This may already be done for you from doing the in class exercises.)

Under the subfolder "lab5" that you just created, you will need to create several files.  The names are of your choosing.  In my example, I called them "orderform.php", "mail.php", "error.php", badcode.php, and "thanx.php".

The lab must contain several items.  Your resulting output should like similar to this.

Title your pages.
Put captions on the top of your pages.
Add a background.

On the first page.  I named mine "orderform.php" :

  • Create a form.
  • Have the user select several items using checkboxes or radio buttons.
  • Have the user fill out some text in a textbox.
  • Have the user provide their email address for confirmation purposes.

Create a separate php file to process the form data.  I named mine "mail.php":

  • Check for the existance of an customer's email address.  If not present, display and error page.
  • Format the information the customer supplied.
  • Send a confirmation email to the customer with the data the user submitted.
  • Send an email to the corporate email account with the data the user submitted.  For testing purposes, send the email to one of your personal accounts first.
  • Hint:  do as I did, check for a test string to be able to test your script at any time.
  • After you have debugged your script, the corporate email account should be "orders at yourdomain dot com".
  • Hint set the return path header in php.ini before sending any email: ini_set('sendmail_from', 'orders at yourdomain dot com); (Replace the at and dot with @ and . and whatever your domain name is.  Spammers are a real pain so I am not even putting email addresses in this website.)

Create an error file to recover from an error.  I named mine "error.php":

  • If the customerr did not enter a confirmation email address, then the user should be directed to this page.
  • Tell the customer what the problem was.
  • Allow the user to go back and fix their mistakes.

Create a thank you page to confirm the submission.  I named mine "thanx.php".:

  • Repeat everything back to the user with the information that they submitted.
  • Thank the customer.

Integrate the captcha code into your mailer to stop spammers from automatically filling out your mail.php form.

Assignment is due 1 week from when it was assigned.  50% penalty if late.

MMDT 1146 Lab 5
Grading Criteria
Date:
Possible
Points
20
Your
Points
20
Pages are titled, captioned, and have a background. 1 1
The orderform.php page has selection buttons, at least one text field, and a textfield for the customer's email address. 3 3
The mail php page checks for the existence of the customer's email address.. 2 2
The mail.php page nicely formats the customer submitted data. 2 2
The mail.php page sends the customer a confirmation email. 2 2
The mail.php page sends an email to the corporate email account. 2 2
The error.php page tells the customer about any errors and allows the user to resubmit their data. 1 1
The thanx.php page repeats the customer entered data and thanks them. 2 2
Captcha code integrated into mail script. 3 3

Lab 5a (Individual homework assignment)

This lab is to test your knowledge of being able to create a php script that sends a confirmation email to the customer and an email to a corporate email account.

Create a subfolder on your web server named "lab5a". 

Under the subfolder "lab5a" that you just created, you will need to create several files.  The names are of your choosing.  In my example, I called them "orderform.php", "mail.php", "error.php", and "thanx.php".

The lab must contain several items.  Your resulting output should like similar to this.

Title your pages.
Put captions on the top of your pages.
Add a background and style your pages.

On the first page.  I named mine "orderform.php" :

  • Create a form.
  • Have the user select several items using checkboxes and radio buttons. There must be at least 10 items with various prices.
  • Have the user fill out some text in a textbox.
  • Have the user provide their phone number and email address for confirmation purposes.

Create a separate php file to process the form data.  I named mine "mail.php":

  • Check for the existance of an customer's phone number and email address.  If not present, display an error page.
  • Format the information the customer supplied.
  • Send a confirmation email to the customer with the data the user submitted.
  • Send an email to the corporate email account with the data the user submitted. In your case the email address will be orders at yourdomain dot com (or something like that).
  • Hint set the return path header in php.ini before sending any email: ini_set('sendmail_from', 'orders at yourdomain dot com');(Replace the at and dot with @ and . and whatever your domain name is.  Spammers are a real pain so I am not even putting email addresses in this website.)
  • Calculate the Total bill.

Create an error file to recover from an error.  I named mine "error.php":

  • If the customerr did not enter a callback phone number or a confirmation email address or pass the captcha, then the user should be directed to this page.
  • Tell the customer what the problem was.
  • Allow the user to go back and fix their mistakes.

Create a thank you page to confirm the submission.  I named mine "thanx.php".:

  • Repeat everything back to the user with the information that they submitted.
  • Thank the customer.

Integrate the captcha code into your mailer to stop spammers from automatically filling out your mail.php form.

Assignment is due 1 week from when it was assigned.  50% penalty if late.

MMDT 1146 Lab 5a (Homework)
Grading Criteria
Date:
Possible
Points
25
Your
Points
25
Pages are titled, captioned, have a background and are styled. 1 1
The orderform.php page has selection radio buttons, checkboxes, and textfields. 3 3
The mail php page checks for the existence of the callback phone number and the customer's email address. 2 2
The mail.php page nicely formats the customer submitted data. 2 2
The mail.php page sends the customer a confirmation email. 2 2
The mail.php page sends an email to the corporate email account. 2 2
The total bill is functional and is calculated correctly. 5 5
The error.php page tells the customer about any errors and allows the user to resubmit their data. 2 2
The thanx.php page repeats the customer entered data and thanks them. 2 2
Captcha code integrated into mail script. 4 4