Top Banner
1 Chapter 2 Chapter 2 Sending form details via Sending form details via emails emails
26

Dynamic Web Pages Ch 2 V1.0

Jan 18, 2015

Download

Technology

Cathie101

 
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dynamic Web Pages Ch 2 V1.0

1

Chapter 2Chapter 2Chapter 2Chapter 2

Sending form details via emailsSending form details via emails

Page 2: Dynamic Web Pages Ch 2 V1.0

2

PHP Sending E-mails• PHP allows you to send e-

mails directly from a script.• The PHP mail() Function• The PHP mail() function is

used to send emails from inside a script.

Page 3: Dynamic Web Pages Ch 2 V1.0

3

Syntax

Note: For the mail functions to be available, PHP requires an installed and working email system. The program to be used is defined by the configuration settings in the php.ini file. Read more in our PHP Mail reference.

Page 4: Dynamic Web Pages Ch 2 V1.0

4

PHP Simple E-Mail• This can be used to check if the

server is setup correctly.

Page 5: Dynamic Web Pages Ch 2 V1.0

5

Sending Emails - 1• 1st check that SMTP is installed.

Through the window component wizard. Highlight IIS and click on details.

• If the SMTP is ticked then it is installed if not you need to install it.

Page 6: Dynamic Web Pages Ch 2 V1.0

6

Sending Emails - 2• Overview:

– In this task you will create a message sent page that will transfer the data to an email.

– The page that obtains the email data is the contact.php page. You will add a table with no borders and a form to send the information to the message_sent.php page.

Page 7: Dynamic Web Pages Ch 2 V1.0

7

Sending Emails - 3• Open the generic_template.php

and save it as message_sent.php• Looks like this

• Make it look like this, with link to index.php.

Page 8: Dynamic Web Pages Ch 2 V1.0

8

Sending Emails – 4• Add the php code as shown.

Page 9: Dynamic Web Pages Ch 2 V1.0

9

Sending Emails - 5• Open contact.php and change it to look like this. Details on

the next slide.

Page 10: Dynamic Web Pages Ch 2 V1.0

10

Sending Emails - 6• Position the insertion point below the image

caption, and choose Insert > Form > Form to create a new form.

• Without moving the insertion point, choose Insert > Table, providing

the following settings. Click OK. – Rows: 4 – Columns: 2 – Width: 95 Percent – Border: 0 – Cell Padding: 3 – Cell Spacing: 0

Page 11: Dynamic Web Pages Ch 2 V1.0

11

Sending Emails - 7• Select the <table> tag using the tag selector,

and use the Property inspector to change its bgcolor (background color) attribute to #eeeeee, which is a light gray.

• In the right column of the table insert the following; – Two text fields called,

• emailAddress• subject

– One text area called body– A Submit button

• In the first three cells of the left column, enter the following text: – Your Email Address – Subject – Message Body

Page 12: Dynamic Web Pages Ch 2 V1.0

12

Sending Emails - 8• Select the text area and give it the

following specifications;– Char Width :55– Num Lines as 6, and Wrap as Virtual.

• Select the form in the tag selector, in the Property inspector set: – Name = frm_message – Action = messageSent.php – Method = POST

• Insert a Heading 2 element above the table that reads, “Send Us a Message.”

Page 13: Dynamic Web Pages Ch 2 V1.0

13

Client-Side Form Validation• Open

contact.php• Select the

submit button• In the behaviours

panels add a behaviour as shown.

Page 14: Dynamic Web Pages Ch 2 V1.0

14

Client-Side Form Validation

• In the Validate form dialog as shown set the fields as– emailAddress: Required as an email– Subject: Required as anything– Body: Required as anything.

• Resulting with the dialog shown below.

Page 15: Dynamic Web Pages Ch 2 V1.0

15

Client-Side Form Validation• Notice the

behaviours panel should look like this when you highlight the submit button.

• Save and test the validation.

Page 16: Dynamic Web Pages Ch 2 V1.0

16

Lab 2 - 1• Overview:

– Create a html form with client-side validation

– Create an action page to send an email.

• Your overview instructions located in the next section of the book: lab section.

• Your two pages will look like the following 2 slides.

Page 17: Dynamic Web Pages Ch 2 V1.0

17

Sendemail.php

Page 18: Dynamic Web Pages Ch 2 V1.0

18

Sendemail_action.php

Page 19: Dynamic Web Pages Ch 2 V1.0

19

Sample of email sent

Page 20: Dynamic Web Pages Ch 2 V1.0

20

Lab 2 - 1• Open server_side_scripting site• Open tourtemplate.php. • Change to Split view. • In the Design view pane, click on the

link Or email us. • In the Property inspector change the

link to link to sendemail.php. Hit the enter key after putting in the link (if you don’t hit enter, the value will not be saved).

• Save tourtemplate.php.

Page 21: Dynamic Web Pages Ch 2 V1.0

21

Lab 2 - 2• Create an Email Form Page

– Save tourtemplate.php as sendemail.php. – Replace the generic left heading with Send

Email. – Replace the generic Left Side Text with the

text “Fill in the values in the form and submit the form to send an email to us. Thank you for your interest.”

– Create a new form below the text. • Name the form email. • Set the action to sendemail_action.php. • Make sure that the Method is Post.

Page 22: Dynamic Web Pages Ch 2 V1.0

22

Lab 2 - 3• Create a table inside the form with 2 columns and 4

rows. – Type in the labels as shown in the table below.

• From Address • Subject • Message Body

– In the second column, • first row put a text field and name it from• With a width of 30 and max of 50.

– In the second row, • put a text field and name it subject• with the same width and max.

– In the third row, • put a textarea control and name it message • with a width of 40 and 10 rows.

– In the last row, – first column put a submit button control – with a label of Send Email.

Page 23: Dynamic Web Pages Ch 2 V1.0

23

Lab 2 – 4• Create Action Page

– Create a new page from tourtemplate.php • name : sendemail_action.php.

– Note that the email link now points to sendemail.php.

• Change the left section title to Email Complete and the text to “Thank you for your email.”

• In bindings, create 3 new Request variables: – from – subject – message

Page 24: Dynamic Web Pages Ch 2 V1.0

24

Lab 2 - 5

•In Code view make space between the heading and the text. Type the following php code.

Page 25: Dynamic Web Pages Ch 2 V1.0

25

Lab 2 - 6• Replace your email address with

mine. The From address would normally be hard coded with the site’s email address.

• Save the page. • Preview the sendemail.php page.

Fill out the form and submit it using your email address as the sender.

Page 26: Dynamic Web Pages Ch 2 V1.0

26

Lab 2 - 7• Client Side Validation

– Return to Dreamweaver and the sendemail.php page. – Select the Submit button. – In the Behaviours panel, click Add Behaviour and

choose Validate Form. – Make all of the fields are required and validate the

email address.

• Save the page. • Preview sendemail.php. • Check that validation is working by trying to

submit an empty form and also try an invalid email address format.