Matthew M.

Matthew M.

Sending Email Using PHP

Slide Duration:

Table of Contents

Course Introduction

12m 13s

Intro
0:00
What Is PHP?
0:12
PHP Hypertext Preprocessor
0:13
Why Learn PHP?
1:09
Why Learn PHP?
1:10
Web Application: Educator Store
2:25
Web Application: Educator Store
2:26
Example of Web Application
3:18
PHP in the Educator Store
7:12
Dynamic Content Generation
7:22
Ease of Website Maintenance
7:55
Form Input Processing and Access to Advanced Functionality
9:00
What You Will Learn
9:36
What You Will Learn
9:37
Who Is This Course For?
10:56
Who Is This Course For?
10:57
How PHP & The Web Work

15m 32s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Client-Server Model
0:53
Client-Server Model
0:54
HTTP Protocol
2:15
Definition of Protocol
2:16
Hypertext Transfer Protocol (HTTP)
2:37
Uniform Resource Locators
3:46
Uniform Resource Locators (URLs)
3:47
Form of URLs
4:13
Accessing Webpages with URLs
5:13
Serving Webpages
6:14
Serving Webpages, Client Machine, and Server Machine
6:15
Static vs. Dynamic Webpages
8:30
Static Webpage
8:31
Dynamic Webpage
8:55
Server-Side Scripting
9:54
Server-Side Scripting
9:55
Static and Dynamic Webpage Coding Example
11:17
Static and Dynamic Webpage Coding Example
11:18
Serving Dynamic Webpages
13:07
Serving Dynamic Webpages
13:08
Setting Up Your Development Environment

33m 11s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Development Environments
1:04
Development Environments
1:05
Our Default Development Environment: Window 7
1:54
Remote Development
4:04
Development Machine & Remote Server
4:05
Local Development
6:54
Development Machine
6:55
Software Used In This Course
9:41
Firefox Web Browser & Firebug Add-On
9:42
XAMPP
12:15
PSPAD Text Editor
13:16
XAMPP Installation
13:49
XAMPP Installation
13:50
Verify XAMPP Install
16:26
Verify XAMPP Install
16:27
localhost
19:08
localhost and 127.0.0.1 'loopback' IP Address
19:09
Document Root
21:16
Document Root and Directory Name
21:17
Document Root for Apache in XAMPP: htdocs & Example
22:13
Text Editor Spectrum
26:12
Text Editor Spectrum: Barebones to IDE
26:13
PSPad & Example
27:02
Finding Help
30:26
Web Resources
30:27
Homework Challenge
31:36
Homework Challenge
31:37
Homework Challenge (cont.)
32:38
Homework Challenge (cont.)
32:39
Your First PHP Script

12m 41s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
.php To HTML
1:00
.php To HTML
1:01
PHP Delimiters
2:20
PHP Delimiters: Opening & Closing PHP Tags
2:21
'Hello, World!' Example
4:34
Echo Statement & PHP Tags
4:35
Adding Second Heading
7:34
Homework Challenge
9:56
Homework Challenge
9:57
Basic PHP Syntax

40m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
PHP Delimiters
0:38
Long and Script Form
0:39
Short and ASP Style
1:33
Example
2:01
php.ini: PHP's Configuration
3:40
php.ini
3:41
Configuration Directives
3:48
Short and ASP Style: Enabled/Disabled
4:13
phpinfo()
7:58
Statements
14:28
PHP Statements
14:29
Example: PHP Statements
14:55
Comments
16:53
PHP Comments
16:55
Single-line Comments
17:37
Multi-line Comments
18:13
Example: PHP Comments
18:47
Coding Conventions
24:26
Coding Conventions
24:27
Example: PHP Coding Conventions
26:19
Homework Challenge #1
33:51
Homework Challenge #1
33:52
Homework Challenge #1 (cont.)
35:41
Homework Challenge #1 (cont.)
35:42
Homework Challenge #2
36:09
Homework Challenge #2
36:10
Homework Challenge #2 (cont.)
38:07
Homework Challenge #2 (cont.)
38:08
Variables & Numeric Data Types

16m 38s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:12
Working With Data
0:48
8 Types of Data for PHP
0:49
Identifiers
1:40
Identifiers: Definition and Example
1:41
Variables
2:47
Variables Definition
2:48
Variables Syntax
3:06
Integer Data Type
4:44
Integer Data Type
4:45
Integer Literals
5:08
Examples
5:30
Float Data Type
6:26
Float Data Type
6:27
Float Literals
7:00
Example
7:21
Example: PHP Code Declaring Variables
8:06
Example: PHP Code Declaring Variables
8:07
var_dump() Function
9:59
var_dump()
10:00
Example: Code and Output
10:30
Example: var_dump() Function
11:19
Coding Conventions: Variables
12:32
Lower Camel Case Notation
12:33
Variable Name Lengths
13:54
Homework Challenge
14:54
Homework Challenge
14:55
String Data Type

18m 6s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
String Data Type
0:29
String Data Type
0:30
Specifying String Literals
1:03
Single-Quoted Strings
1:53
Single-Quoted Strings
1:54
Escape Sequences
2:31
Escape Sequences
2:32
Example
2:46
Escape Sequences for Commonly Used Special Characters
4:32
Double-Quoted Strings
6:04
Double-Quoted Strings
6:05
Variable Interpolation
6:44
Coding Conventions: Strings
7:54
Coding Conventions: Strings
7:55
Homework Challenge
8:54
Homework Challenge
8:55
Include Files & Web Application Introduction

38m 43s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
include Statement
0:47
include Statement: Definition
0:48
Include Statement: Syntax
2:05
include Statement: Example
2:25
include Path
6:32
Absolute and Relative Path
6:34
Specified Path
7:15
Not Specified Path
7:55
Code Reuse
9:35
Code Reuse
9:36
Example
11:11
require Statement
12:56
require Statement: Definition
12:57
require Statement: Syntax
13:32
Include versus Require
13:52
Coding Conventions
16:33
Coding Conventions
16:34
Introduction to Our Web Application
20:32
Introduction to Our Web Application
20:33
Updating Web Application
21:14
Web Application Example
22:59
Homework Challenge
35:33
Homework Challenge
35:34
Homework Challenge (cont.)
37:38
Homework Challenge (cont.)
37:39
Arrays

34m

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is an Array?
0:42
What is an Array?
0:43
Arrays in PHP
1:44
Keys and Values
2:15
Types of Arrays
3:37
Indexed Arrays & Associative Arrays
3:38
array() Construct
6:47
Declaring Arrays
6:48
Defining Indexed Array
7:00
Defining Associative Arrays
7:43
Square Bracket Syntax
8:50
Square Bracket Syntax
8:51
Accessing Indexed Arrays
9:02
Accessing Associative Arrays
9:56
Arrays Example
10:41
Indexed Arrays Example
10:45
Associative Arrays Example
13:55
Multi-Dimensional Arrays
18:28
Multi-Dimensional Arrays
18:29
Multi-Dimensional Arrays Example
18:51
Multi-Dimensional Arrays in PHP File
20:34
Coding Conventions: Arrays
27:59
Coding Conventions: Arrays
28:00
Homework Challenge #1
29:20
Homework Challenge #1
29:21
Homework Challenge #2
30:38
Homework Challenge #2
30:39
Web Application Development

27m 38s

Intro
0:00
Versions
0:14
Version 3.0
1:23
Version 3.1
8:08
Version 3.2
11:42
Version 3.3
20:27
Homework Challenge
26:31
Homework Challenge
26:32
Script Input & The GET Method

30m 18s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Providing Input to PHP
0:39
GET Method, POST Method, and Cookies
0:40
Name/Value Pairs
1:22
GET Method
1:57
HTTP GET Method
1:58
Query String
2:52
GET Method Example
3:38
GET Method Example
3:39
Review of HTML Forms
8:16
HTML Forms
8:17
Input Control and Submitted Form
9:13
<form> Tag
10:07
<form> Tag
10:08
Method
10:34
Action
11:13
Input Control Examples
11:50
Input Control Examples
11:51
Common Input Controls
17:31
Common Input Controls
17:32
Query Strings
18:52
Query Strings
18:53
Query Strings Syntax
19:12
URL Encoding
20:01
URL Syntax
20:02
Examples
21:17
Simple Form Example
22:28
urlencode() Function
24:08
urlencode() Function
24:09
Example
25:03
urlEncoding Text Example
25:54
Simple Form Example
25:55
Homework Challenge
28:46
Homework Challenge
28:47
Accessing Form Data in PHP

32m 1s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
$_GET Array
0:48
$_GET Array
0:49
Accessing the Value of a Name/Value Pair Submitted Via GET
1:04
Name Form Example
2:54
Name Form and the $_GET Array
2:55
Using Arrays with Input Controls
6:34
Using Arrays with Input Controls
6:35
Common Example
6:47
Indexed Array Form Example
8:16
Indexed Array Form Example
8:17
Associative Arrays with Input Controls
10:14
Associative Arrays with Input Controls
10:15
Associative Arrays Example
11:41
Associative Arrays Example
11:42
Echo Form Example
15:18
Echo Form Example
15:19
Outputting Arrays In String
23:42
Variable Interpolation
23:43
Outputting a Value in an Indexed Array Within a String
24:12
Simple' Syntax, 'Complex' Syntax, and 'Curly Brace' Syntax
25:00
Outputting Arrays In String Example
26:25
Outputting Arrays In String Example
26:26
Homework Challenge
29:39
Homework Challenge
29:40
Web Application Development

20m 20s

Intro
0:00
Lesson Overview
0:19
Lesson Overview
0:20
Version 3.3
0:38
Version 3.3
0:42
Version 4.0 Changelog
2:43
GET Query
2:45
Adding, Editing, and Removing
3:24
Version 4.0 Coding Example
3:55
item.php, itemID, and itemListing
4:00
Version 4.1 Changelog
10:36
Version 4.1 Changelog
10:37
Version 4.1 Coding Example
11:45
Adding Checkout and Thank You & Editing Footer and Store
11:46
Homework Challenge
18:45
Homework Challenge
18:46
Expression & Operators

31m 56s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Expressions
0:41
Expressions Definition
0:42
Example: Literals
0:55
Example: Variables
1:05
Operators
1:44
Operators Definition
1:45
Unary, Binary, and Ternary Operators
2:07
Assignment Operators
2:52
Assignment Operators
2:53
Array Assignment Operator
3:47
Arithmetic Operators
6:15
Operators for Common Arithmetic Operations
6:16
Modulus Operator
7:41
Arithmetic Operators Example
8:25
Increment/Decrement Operators
10:48
Increment/Decrement Operators
10:49
Pre- and Post- Increment/Decrement
12:43
Coding Example
15:14
Combined Assignment Operators
16:44
Combined Assignment Operators
16:45
Combined Assignment Operators Examples
18:23
Coding Example
19:39
String Operators
20:28
Concatenation Operator, String Variables, and String Literals
20:29
String Operators Example
22:41
Precedence & Associativity
23:40
Precedence & Associativity
23:41
Expression Containing Multiple Operations
23:58
Expression Containing Two Operations of Equal Precedence
25:55
Using Parentheses to Force Precedence
26:52
Precedence & Associativity Review
28:57
Homework Challenge
31:08
Homework Challenge
31:09
Web Application Development

20m 51s

Intro
0:00
Lesson Overview
0:15
Lesson Overview
0:16
Version 4.1 Review
0:33
Version 4.1 Review
0:34
Version 5.0 Changelog
1:05
Version 5.0 Changelog
1:06
Version 5.0 Example
2:19
Adding View Cart & Editing Checkout, Footer and Store
2:20
Version 5.1 Changelog
15:36
Version 5.1 Changelog
15:37
Version 5.1 Coding Example
17:33
Forwarding Order Total to Thank You Page
17:34
Homework Challenge
20:09
Homework Challenge
20:10
Boolean & Null Data Types

20m 11s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Boolean Data Type
0:38
Boolean Data Type
0:39
Two Boolean Literals
1:24
Boolean Example
1:50
Boolean Example
1:51
Comparison Operators
4:00
Comparison Operators Definition
4:01
Common Comparison Operators
4:40
Comparison Operators Example
6:49
Comparison Operators (Cont.)
10:10
Identical and Not Identical
10:11
Example: Identical and Not Identical
11:24
Null Data Type
13:36
Null Data Type Definition
13:37
Null Literal
14:08
Variable and Null Data Type
14:30
'==' Operator
15:24
Null Data Type Example
15:59
Coding Convention
18:41
Coding Convention
18:42
Homework Challenge
19:17
Homework Challenge
19:18
Type Casting

22m 41s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Type Juggling
0:54
Type Juggling
0:55
Automatic Conversion
2:23
Type Casting
3:53
Type Casting
3:54
Implicit and Explicit Type Casting
4:00
Explicitly 'cast' a Variable Example
4:16
Type Casting (cont.)
6:48
PHP Allows the Following Explicit Type Casts
6:49
The settype () Function
8:18
Type Casting Coding Example
9:00
Explicit Type Casts
9:01
String Conversions
14:52
String Conversions
15:05
Common Conversions to String
15:55
Numeric Conversions
18:18
Numeric Conversions
18:19
Boolean Conversions
20:29
Boolean Conversions
20:30
Homework Challenge
21:38
Homework Challenge
21:39
Introduction to Functions

52m 20s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
What are Functions?
0:51
Definition of Faction
0:52
PHP and Function Call
1:53
Function Calls
2:42
Function Calls
2:43
Function Arguments
3:17
Return Values
4:56
Return Values
4:57
Function Chaining
6:29
Function Chaining
6:30
PHP.net Function Reference
8:23
PHP.net & Function Prototypes
8:24
PHP.net Function Reference Example
9:29
Optional Function Arguments
12:28
Optional Function Arguments
12:29
String Functions
14:57
strtoupper() and strtolower()
14:58
implode (), str_replace(), explode(), strpos(), substr(), and strlen()
18:31
Array Functions
25:48
count()
25:49
in_array() and array_key_exists()
26:06
sort() and ksort()
26:37
Example: count() and in_array()
27:50
Example: array_key_exists()
29:53
Example: sort() and ksort()
31:20
Date & Time Functions
33:38
date() and time()
33:39
getdate()
34:49
mktime()
35:01
Date & Time Functions
35:12
Example: date() and time()
35:58
Example: getdate()
42:15
Example: mktime()
43:15
Homework Challenge #1
44:31
Homework Challenge #1
44:32
Homework Challenge #1 (Cont.)
45:28
Homework Challenge #1 (Cont.)
45:29
Homework Challenge #2
46:34
Homework Challenge #2
46:34
Homework Challenge #2 (Cont.)
48:06
Homework Challenge #2 (Cont.)
48:07
Homework Challenge #2 (Cont.)
49:17
Homework Challenge #2 (Cont.)
49:18
Homework Challenge #3
50:08
Homework Challenge #3
50:09
Constants

19m 24s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Constants vs. Variables
0:55
Constants vs. Variables
0:56
Constant Identifiers
2:28
Constant Identifiers Definition and Examples
2:29
Declaring Constants
3:47
Two Ways of Declaring Constants
3:48
Syntaxes
4:10
Major Difference in the Two Forms
4:48
Using Constants Example
6:25
Using Constants Example
6:26
Coding Conventions
11:08
Constant Names
11:09
define () Function
11:42
Meaningful Names
12:00
$_SERVER Superglobal
12:23
$_SERVER
12:24
$_SERVER ['DOCUMENT_ROOT']
13:15
$_SERVER Superglobal Example
13:52
Homework Challenge
17:40
Homework Challenge
17:41
Web Application Development

26m 29s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 6.0
1:13
Version 6.0 & Version 5.1 Review
1:14
Version 6.0 Changelog
11:24
Version 6.0 Changelog
11:25
Version 6.1 Changelog
12:00
Version 6.1 Changelog
12:01
Version 6.1 Coding Example
12:42
Version 6.1 Coding Example
12:43
Version 6.2 Changelog
15:18
Version 6.2 Changelog
15:19
Version 6.2 Coding Example
18:19
Version 6.2 Coding Example
18:20
Homework Challenge
25:24
Homework Challenge
25:25
Conditional Control Structures

18m 58s

Intro
0:00
Lesson Overview
0:26
Lesson Overview
0:27
Statement Groups
0:57
Statement Groups
0:58
Example
1:10
Conditional Control Structures
1:38
Conditional Control Structures
1:39
PHP Control Structures
1:56
if Statement
2:32
if Statement
2:33
if Statement (cont.)
3:49
if Statement Coding Example
3:50
else Statement
7:26
else Statement
7:27
if/else Statement Coding Example
8:50
isset() Construct
9:59
isset() Construct
10:00
isset() Construct Coding Example
12:00
Coding Conventions
15:13
Coding Conventions
15:14
Coding Conventions (Cont.)
16:39
Coding Conventions (Cont.)
16:40
Homework Challenge
17:25
Homework Challenge
17:26
Error Handling

19m 8s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Error Handling in PHP
0:41
Error Handling in PHP
0:42
Coding Example
1:45
error_reporting() Function
7:02
error_reporting() Function
7:03
Coding Example
8:04
Additional Error Directives
9:02
display_errors
9:13
log_errors
9:37
error_log
9:50
track_errors
10:12
Coding Examples
10:29
Error Control Operator
13:38
Error Control Operator & Coding Example
13:39
Homework Challenge
16:19
Homework Challenge
16:20
Homework Challenge (cont.)
17:58
Homework Challenge (cont.)
17:59
Logical & Ternary Operators

23m 22s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
Logical Operators
0:49
Logical Operators Definition
0:50
NOT (!)
1:08
OR ( ||, or)
1:35
AND (&&, and)
2:08
XOR (xor)
2:30
Logical Operators (cont.)
2:54
The OR and AND Logical Operators
2:55
Precedence of Logical Operators
3:35
Logical Operators Coding Example
3:58
Logical Operators Coding Example
3:59
Short-Circuit Operators
9:54
Short-Circuit Operators
9:55
Coding Example
10:49
Ternary Operator
14:07
Ternary Operator
14:08
Syntax and Example
14:24
Coding Conventions
17:36
Coding Conventions
17:37
Homework Challenge
19:08
Homework Challenge
19:09
Homework Challenge (cont.)
20:26
Homework Challenge (cont.)
20:27
Web Application Development

19m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 6.2 Review
0:26
Version 6.2 Review
0:27
Version 7.0 Changelog
2:39
Version 7.0 Changelog
2:40
Version 7.0 Coding Example
4:35
Version 7.0 Coding Example
4:36
Version 7.1 Changelog
12:43
Version 7.1 Changelog
12:44
Version 7.1 Coding Example
13:52
Version 7.1 Coding Example
13:53
Homework Challenge
17:42
Homework Challenge
17:43
More Conditional Control Structure

20m 49s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
elseif Statement
0:45
elseif Statement
0:46
elseif Statement Coding Example
1:22
Multiple elseif Statements
2:16
Multiple elseif Statements
2:17
Multiple elseif Statements Coding Example
3:07
Adding an else Statement
5:44
Adding an else Statement Overview
5:45
Adding an else Statement Coding Example
6:50
switch() Statement
8:07
switch() Statement
8:08
switch() Statement (Cont.)
9:14
switch() Statement (Cont.)
9:15
switch() Statement Coding Example
11:09
default Case
14:20
default Case
14:21
default Case Coding Example
15:13
Coding Conventions
15:57
Coding Conventions
15:58
Coding Conventions (cont.)
17:10
Coding Conventions (cont.)
17:11
Homework Challenge
18:06
Homework Challenge
18:07
Homework Challenge (cont.)
19:18
Homework Challenge (cont.)
19:19
Nested Conditional Control Structures

24m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Nested Control Structures
0:36
Nested Control Structures
0:37
Nested Control Structures Coding Example
2:08
Coding Conventions
6:34
Nested vs. Not Nested Control Structures
6:35
Debugging Control Structures
7:51
Debugging Control Structures
7:52
Incorrectly Specified Test Conditions and Forgetting a Break Statement
8:32
Incorrectly Placing an Opening or Closing Curly Brace
12:14
Debugging Tips
16:24
Tracing the Execution of Your Code
16:25
Adding Echo Statement
17:15
Homework Challenge
21:41
Homework Challenge
21:42
Homework Challenge (cont.)
23:08
Homework Challenge (cont.)
23:09
Web Application Development

28m 20s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 7.1 Review
0:46
Version 7.1 Review
0:47
empty () Construct
1:38
empty () Construct
1:39
empty () Construct Coding Example
2:37
Version 8.0
5:32
Version 8.0 Overview
5:33
Version 8.0 Coding Example
7:08
Version 8.0 Coding Example
7:09
Version 8.1
16:13
Version 8.1 Overview
16:14
Version 8.1 Coding Example
19:48
Version 8.1 Coding Example
19:49
Homework Challenge
26:19
Homework Challenge
26:20
Sending Email Using PHP

43m 50s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
Built-in Mail Extension
1:28
Built-in Mail Extension
1:29
SMTP Overview
2:04
SMTP Overview
2:05
SMTP - Windows
3:08
SMTP - Windows
3:09
SMTP - Linux/UNIX
4:58
SMTP - Linux/UNIX
4:59
Mail Configuration Directives
6:35
Mail Configuration Directives
6:36
Coding Example
7:48
Mail Server Authentication
10:20
Mail Server Authentication
10:21
fake sendmail Program
12:27
fake sendmail for Windows
12:28
Main 'add-on' feature
13:03
Username & Password
13:25
SMTP - XAMPP for Windows
14:07
SMTP - XAMPP for Windows
14:08
Sendmail Example
16:19
Sendmail Example
16:20
mail() Function
18:39
mail() Function
18:40
additional_headers
19:45
'From' Header
20:12
mail() Function Coding Example
21:09
mail() Function Coding Example
21:40
Web Application Development
31:43
Version 9.0 Changelog
31:44
ContactUs.php
32:52
ContactUs.php
32:53
contactInfo
33:45
Version 9.0 Coding Example
34:31
Version 9.0 Coding Example
34:32
Homework Challenge
41:32
Homework Challenge
41:33
User-Defined Functions

56m

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Defining Functions
1:29
Four Parts of Defining a Function
1:30
Functions Example 1
2:29
Function Parameters
5:29
Function Parameters
5:30
Functions Example 2
8:20
Return Statements
12:53
Return Statements
12:54
Functions Example 3
14:20
Where to Define Functions
20:34
Where to Define Functions
20:35
include_once Construct
22:10
include_once Construct
22:11
include_once Coding Example
23:55
Reasons to Use Functions
27:44
Take Advantage of Code Reuse
27:45
Improve Code Readability
29:56
Use Instead of 'content' Include Files
32:12
Web Application Development
34:42
Version 10.0 Changelog
34:43
Version 10.0 Coding Example
37:55
Version 10.0 Coding Example
37:56
Outputting HTML in Functions
47:04
Outputting HTML in Functions
47:05
Example
49:02
Coding Conventions
53:16
Coding Conventions
53:17
Homework Challenge
54:33
Homework Challenge
54:34
Variable Scope

31m 37s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is Variable Scope?
0:57
Variable Scope
0:58
Global Scope
1:15
Local Function Scope
1:50
Variable Scope Coding Example
2:26
Variable Scope Coding Example
2:27
global Keyword
8:52
global Keyword Overview
8:53
global Keyword Example
9:25
Superglobals
12:34
Superglobals
12:35
Superglobals Example
14:53
Pitfalls of Global Variables
18:34
Pitfalls of Global Variables
18:35
When to Define Variables
22:09
When to Define Variables
22:10
Putting It All Together
22:56
Putting It All Together Example
22:57
Function Scope
28:56
Function Scope
28:57
Homework Challenge
29:41
Homework Challenge
29:42
Homework Challenge (cont.)
30:59
Homework Challenge (cont.)
31:00
Web Application Development

28m 27s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 11.0 Changelog
0:56
Version 11.0 Changelog
0:57
processGetVar()
1:42
processGetVar() Overview
1:43
processGetVar() Example
2:25
emailComments()
6:35
emailComments() Overview
6:36
emailComments() Example
7:14
outputItemLink()
11:19
outputItemLink() Overview
11:20
outputItemLink() Example
11:45
calcCartTotal()
19:25
calcCartTotal() Overview
19:26
calcCartTotal() Example
21:14
Homework Challenge
25:56
Homework Challenge
25:57
Optional Parameters

19m 35s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Optional Parameters
0:26
Optional Parameters Definition
0:27
Default Values
0:53
Optional Parameters Coding Example
3:26
More on Optional Parameters
6:55
Multiple Optional Parameters
6:56
Coding Example
8:05
Homework Challenge
16:18
Homework Challenge
16:19
Web Application Development

23m 7s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Version 12.0 Changelog
0:55
Version 12.0 Changelog
0:56
Update to outputLink()
1:44
Update to outputLink()
1:45
outputLink() Coding Example
2:40
outputImg()
13:57
outputImg() Overview
13:58
outputImg() Coding Example
15:35
Homework Challenge
22:05
Homework Challenge
22:06
Introduction to Conditional Loops

57m 20s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
while Loop
0:48
Definition
0:49
Syntax and Usage
1:12
Coding Example
3:33
Looping Over Arrays
13:16
Looping Over Arrays
13:17
Coding Example
13:53
Looping Over Arrays (cont.)
16:43
Internal Array Pointer
16:44
Array Traversal Functions
17:29
current ()
17:30
next () and prev ()
18:16
reset () and end ()
19:25
key ()
19:40
Indexed Arrays: Using current () and next ()
20:40
Indexed Arrays: Using current () and next ()
20:41
Associative Arrays: Using key (), current (), and next ()
24:06
Associative Arrays: Using key (), current (), and next ()
24:07
Array Traversal Functions (cont.)
29:41
list () Construct and Example
30:07
each () Construct and Example
34:40
Lopping Over Arrays Using list(), each()
42:13
Lopping Over Arrays Using list(), each()
42:14
Control Structure Scope
50:37
Definition and Example
50:38
Control Structure Scope Coding Example
51:59
Coding Conventions
54:20
Coding Conventions
54:21
Homework Challenge
54:58
Homework Challenge
54:49
More on Conditional Loops

35m 50s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
do-while Loop
0:42
do-while Loop
0:43
Simple do-while Loop Example
1:51
Another do-while Loop Example
4:09
continue Statement
10:46
continue Statement
10:47
For Example
11:07
continue Statement Coding Example
12:44
break Statement Re-Visited
18:10
break Statement Re-Visited
18:11
break Statement In while Loops Example
19:38
Infinite Loops
23:26
Infinite Loops
23:27
Coding Example
24:57
Common Loop Pitfalls
25:59
Counter Initialization Occurs in Loop
26:30
Counter Not Incremented in Loop
29:30
Unreachable Break Statement
30:50
Coding Conventions
33:48
Do-while Statements Coding Conventions
33:49
Homework Challenge
34:28
Homework Challenge
34:29
Web Application Development

22m 7s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 13.0 Changelog
0:48
Updating 'viewCart.php' and calcCartTotal()
0:49
Creating isValidCart()
9:22
Adding Three New Item to the Store & Links
15:56
Version 13.1 Changelog
17:20
Updating outputItemLink() to Remove Its Global Dependency on $itemCatalog
17:21
Homework Challenge
20:34
Homework Challenge
20:35
For & Foreach Loops

29m 28s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
for Loops
0:45
for Loops
0:46
Expression 1
1:22
Expression 2
1:47
Expression 3
2:01
Simple Example
2:27
Simple Example
2:28
Notes on for Loops
8:56
Notes on for Loops
8:57
Ending Loop Using Test Condition and Break Statement
10:06
Ending Loop Using Test Condition and Break Statement
10:07
foreach Loops
12:03
foreach Loops
12:04
Indexed Array Syntax
14:10
Syntax
14:11
Example
15:23
Associative Array Syntax
18:31
Syntax
18:32
Example
19:47
Coding Conventions
25:05
for Loops
25:06
foreach Loops
25:58
Homework Challenge
26:52
Homework Challenge
26:53
Web Application Development

25m 58s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Version 14.0 Changelog
1:19
Version 14.0 Changelog
1:20
Version 14.0 Coding Example
1:57
Version 14.0 Coding Example
1:59
Version 14.1 Changelog
5:39
Version 14.1 Changelog
5:40
Version 14.1 Coding Example
7:06
Version 14.1 Coding Example
7:07
Version 14.2 Changelog
15:37
Version 14.2 Changelog
15:38
Version 14.2 Coding Example
16:25
Version 14.2 Coding Example
16:26
Homework Challenge
23:35
Homework Challenge
23:36
Conditional Loop Wrap-Up

23m 12s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Nested Conditional Loops
0:39
Nested Conditional Loops
0:40
Coding Example
1:10
continue & break Re-Visited
5:17
Continue Statements and Coding Example
5:30
Break Statements and Coding Example
11:34
Loop Debugging Tips
15:16
Add Short Debug Statement At the Very Beginning
15:17
Output a Counter Variable
18:10
Add Debug Statement At the Very End
19:20
Homework Challenge
20:20
Homework Challenge
20:21
Homework Challenge (cont.)
22:00
Homework Challenge (cont.)
22:01
Variable-Length Parameter Lists

22m 16s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Variable-Length Parameter Lists
0:34
Variable-Length Parameter Lists
0:35
Coding Example
1:51
Variable-Length Parameter Lists (cont.)
5:21
When a Parameter List is Defined For the Functions
5:22
Coding Example
6:32
Variable Type Functions
9:54
is_int (), is_float (), is_string (), and is_bool()
9:55
is_ array ()
10:50
is_null ()
11:01
Variable Type Functions Coding Example 1
11:27
is_numeric() and Example
15:57
Variable Type Functions Coding Example 2
17:12
Homework Challenge
19:35
Homework Challenge
19:36
Homework Challenge (cont.)
20:52
Homework Challenge (cont.)
20:53
Web Application Development

38m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
Version 15.0 Changelog
0:33
outputLink (), outputImg (), is_array () and is_string ()
0:34
Version 15.0 Coding Example
1:31
Version 15.0 Coding Example
1:32
Version 15.1 Changelog
7:55
Removing Redundant Code and Adding New Function Called outputHtmlTag ()
7:56
Version 15.1 Coding Example
8:37
Version 15.1 Coding Example
8:38
Version 16.0 Changelog
14:55
Creating emailOrder() Using New Constants ORDER_EMAIL_FROM and ORDER_EMAIL_SUBJECT
14:56
Version 16.0 Coding Example
16:30
Version 16.0 Coding Example
16:31
Version 16.1 Changelog
32:21
Creating formatAsDollars ()
32:22
Version 16.1 Coding Example
32:57
Version 16.1 Coding Example
32:58
Homework Challenge
36:27
Homework Challenge
36:28
Miscellaneous Topics

31m 49s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
register_globals Directive
0:58
register_globals
0:59
Coding Example
2:04
$_GET vs. $HTTP_GET_VARS
4:07
$_GET vs. $HTTP_GET_VARS
4:08
register_long_arrays Directive Coding Example
5:44
Magic Constants
7:30
Magic Constants
7:31
__LINE__, __FILE__, __FIR__, and __FUNCTION__
8:16
Coding Example
9:06
exist() & die()
13:19
exist() & die()
13:20
Coding Example
14:08
Execution Operator
16:23
Execution Operator
16:24
Coding Example
17:27
Array Operators
18:23
Equality (==) and Inequality (!=, <>)
18:43
Identity (===) and Non-Identity (!==)
19:13
Union (+) Operator
19:41
Array Operators Coding Example
20:07
Variable Variables
24:13
Variable Variables
24:14
Coding Example
26:07
Variable Functions
28:02
Variable Functions
28:03
Coding Example
29:13
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Introduction to PHP
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (8)

0 answers

Post by Adil Alkarkhi on August 6, 2013

How can I find sendmail.ini? any help please?

1 answer

Last reply by: sorin dragon
Mon Mar 14, 2016 4:43 PM

Post by John Cox on April 26, 2013

I am using a PC with Windows 7. I don't have any "local" email, i.e. DSL provider. I do have accounts on yahoo, gmail and mail.com. I do not have a dedicated IP address from my PC. I have tried for hours without success to configure sendmail and also tried Mercury (from XAMPP). The only way to avoid an 'Error Sending Email' is to configure php.ini to use mailtodisk.exe as sendmail_path = "C:\Users\larry\xampp\mailtodisk\mailtodisk.exe". This works only to the extent that there is no error, but of course there is no email sent or received. Is the problem in using sendmail as sendmail_path = "\"C:\Users\larry\xampp\sendmail\sendmail.exe\" -t" due to the fact that I cannot use localhost for my mail server?

0 answers

Post by Okoa Kinesy on November 23, 2012

Hi Matthew I am trouble send my email from the php script. The script is returning the string "email sent successfully". However it does this even if I reset the ini files to their default values (ie. "smtp_server=localhost" in sendmail.ini). So it seems like the script is not communicating with the ini files. Any suggestions?

1 answer

Last reply by: Anthony Reynolds
Thu Jul 5, 2012 5:09 PM

Post by Anthony Reynolds on July 5, 2012

Matthew,

1 answer

Last reply by: Matthew M.
Tue Feb 7, 2012 4:26 AM

Post by DANIEL VACA on December 12, 2011

I can only get contatctUs.php to work if $contactInfo['email'] is set to a validated email. But to get the email validated I need to also have the password.

That is, I can get contatctUs.php to send TO any email; But I can only get it to send FROM emails that I own.

Sending Email Using PHP

  • PHP provides the built-in mail() function to send email messages from scripts.
  • The Simple Mail Transfer Protocol, or SMTP , is the protocol used to send and receive email messages on the Internet. It is implemented by mail servers .
  • php.ini can be configured so that mail() will work in either a Windows or Linux/UNIX environment.
  • When in a Windows environment, the configuration directive SMTP is typically set. When in a Linux/UNIX environment, the configuration directive sendmail_path is typically set.
  • Mail servers typically require an email client to authenticate themselves before they will relay their email message to the recipient.
  • fake sendmail for Windows is an application included with XAMPP that allows the sending of emails using mail() with mail servers requiring authentication.
  • sendmail.ini is the fake sendmail configuration file used to specify a username and password to use for authentication.
  • The additional_headers argument of mail() is used to specify who an email is from by specifying a ‘From’ header that takes on the form: 'From: [email protected]' .
  • Additional Resources:

Sending Email Using PHP

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:14
    • Lesson Overview
  • Built-in Mail Extension 1:28
    • Built-in Mail Extension
  • SMTP Overview 2:04
    • SMTP Overview
  • SMTP - Windows 3:08
    • SMTP - Windows
  • SMTP - Linux/UNIX 4:58
    • SMTP - Linux/UNIX
  • Mail Configuration Directives 6:35
    • Mail Configuration Directives
    • Coding Example
  • Mail Server Authentication 10:20
    • Mail Server Authentication
  • fake sendmail Program 12:27
    • fake sendmail for Windows
    • Main 'add-on' feature
    • Username & Password
  • SMTP - XAMPP for Windows 14:07
    • SMTP - XAMPP for Windows
  • Sendmail Example 16:19
    • Sendmail Example
  • mail() Function 18:39
    • mail() Function
    • additional_headers
    • 'From' Header
  • mail() Function Coding Example 21:09
    • mail() Function Coding Example
  • Web Application Development 31:43
    • Version 9.0 Changelog
  • ContactUs.php 32:52
    • ContactUs.php
    • contactInfo
  • Version 9.0 Coding Example 34:31
    • Version 9.0 Coding Example
  • Homework Challenge 41:32
    • Homework Challenge

Transcription: Sending Email Using PHP

Hello again, and welcome back to Educator.com's Introduction to PHP course.0000

Today's lesson is going to be a rather fun lesson, because we are going to be learning about how to use PHP's built-in mail function,0004

which is going to allow us to send emails from our PHP scripts.0010

Specifically, we are going to talk a little bit about the built-in extension.0016

And then, we are going to go over some basics of SMTP, which stands for Simple Mail Transfer Protocol.0021

And what that is: that is how email messages get transferred from a sender to a recipient on the Internet.0028

So, we are going to talk a little bit about that, and we are going to talk about how it works in both Windows and in a Linux or UNIX operating environment.0034

We are going to talk about some mail configuration directives that are within php.ini.0042

We are going to go over a little bit about mail server authentication.0049

And then, talk about a program provided by XAMPP called fake sendMail for Windows,0053

which allows you to send email from your PHP programs with a little bit more flexibility than comes built into PHP by itself.0059

And specifically, we are going to talk about the function that does it all, which is the mail function,0070

which is the built-in function of PHP that allows you to send email.0075

And then, we are going to update our web application to include a contactUs page that is going to allow a customer to email the store administrator.0078

As mentioned, PHP provides a built-in mail extension, and what it does is: it provides two functions, but the main function that is used is this function here, mail.0090

What that allows you to do is send emails from your PHP scripts.0103

Now, in order to use the mail function from your scripts, there are several configuration directives that you will need to set up in php.ini.0107

And we are going to walk through that, but before we do that, I am going to go and give a little bit of overview about how email on the Internet works.0118

SMTP, or as it is known, Simple Mail Transfer Protocol, is the protocol that is used between servers on the Internet to exchange email.0126

When you send an email from one email address to another,0138

SMTP is the rules that are used to get that email from where it originated to where it's going.0142

The protocol is implemented by things known as mail transfer agents, or MTA's,0150

Or, as they are more commonly known, and you have probably heard them referred to as, a mail server.0156

And whenever you send an email from an email client like Outlook or via a web-based email like Gmail,0161

your message gets sent along to a mail server, an SMTP server, as it is sometimes referred to,0169

which will relay it (pass the message along) to the recipient's receiving mail server.0176

Now, I just want to go over how this works in Windows, because there is a little bit of difference between0190

how email is sent, typically, in Windows, and in a Linux and UNIX operating system.0194

We have a diagram here, and we have a client computer, and this little symbol is for the Thunderbird email client.0201

It is free from Mozilla, and it is an email client used to send and receive emails.0214

What happens is: when you are in Thunderbird on your computer, your Thunderbird application--when you go to send an email,0219

it contacts a mail server, typically on your local network, and it sends a message to it by SMTP.0227

What happens is: once the mail server receives that message, it reads it and figures out where it needs to go.0237

And it sends it through the Internet over to whoever the recipient is, whatever domain they reside on.0244

It is going to send it to their mail server, and it is going to use SMTP to do that.0252

And then, what happens is: when the client on the other side, the recipient, opens up their Thunderbird client0257

(let's say they are using Thunderbird as well) to download their email, typically what happens is: they will download their email0264

from the mail server, using what you might have heard of as the POP or IMAP protocols.0269

We are not really going to be talking about that too much in this lesson.0278

We are going to be concerned with the sending of email, so we are going to talk about the SMTP structure.0280

So, in Windows, this is typically how it works: you have an email being sent from your client, and it is sent to a mail server,0285

which sends it out over the Internet; and the mail server is typically on your local network.0292

Now, the typical setup in a Linux or UNIX environment is a little bit different.0299

In this case, we have as our client PHP; and an email client typically refers to something that sends or receives email.0304

And because we are going to be sending email from PHP, we can consider PHP a client.0311

Now, if you notice, there is no mail server over here, like there was in the setup.0317

On a typical Linux setup, there is a program called sendmail, which you may have heard of before, which is its own mail server.0322

So, typically, we already have PHP running; it has sendmail running on the same computer.0334

So, instead of forwarding a message by SMTP out to a local mail server, who will then forward it along to the client,0339

like this, what happens is: PHP or your mail client (you can do Thunderbird, as well) will send the message along to the local sendmail program running.0349

And then, what sendmail does is: that is the actual mail server, and it is the one that goes out through the Internet0361

and, via SMTP, sends it along to the client's mail server.0368

And then, same as before, the recipient can download it by a POP or IMAP to read the email.0373

The main difference here is that typically, on Linux, you have your SMTP server running on the same computer as your email client.0381

Now, as mentioned, php.ini provides a number of configuration directives that allow you to configure how the mail function is going to work.0396

And the way you set the configuration directives depends on whether you are going to be in a Windows environment or in a Linux or UNIX environment.0406

Typically, when you are using a Windows environment, you are going to be setting a directive called SMTP.0416

What that does is: that allows you to specify the name of your local email server that you are going to use to send out your messages.0422

In our diagram, that was that first server, where the client passed the email along to be sent out over the Internet.0432

In Linux environment, you are going to be using, typically, the directive sendmail_path.0439

What that does is: that gets set to the location of where the sendmail program is on your local machine,0443

because, as we said, sendmail runs on the same machine as your email client or PHP.0451

With the sendmail_path, we actually specify the file location of that sendmail program or sendmail binary.0457

And that way, PHP knows how to invoke the sendmail program to get it to send the email out over the Internet.0463

If we go and take a look...if we open up php.ini, quite a ways down the page,0469

in the section where extensions are configured, there is a section called Mail Function.0477

You can see a couple of directives here: here is the SMTP directive that we talked about; and this, as mentioned, says "For Win32 only."0485

This is typically what is used in the Windows environment.0494

What you would do is set it to your local SMTP server, and that is going to depend on what you use for your email.0497

For a lot of people, if you have, for example, cable Internet or DSL, your cable Internet provider or ISP0507

gives you the name of a server you can use as an SMTP server, which allows you to send email.0517

For example, sometimes Road Runner is like a Time Warner cable Internet service.0522

Often, their SMTP server that they give to you is called something like smtp-server.roadrunner.com.0531

And so, what that does is...what this directive is saying is: that is telling PHP that, when it sends an email using the mail function,0541

that it is supposed to send the email to this SMTP server on your local network,0553

and then, to have that SMTP server actually send it out over the Internet.0561

We will set this back to its default value.0567

Now, the other directive we talked about was the sendmail_path; and this, as you can see, says "for UNIX and Linux."0573

What that is: if you look further down, it is basically a path to the sendmail binary, which is a sendmail program that runs on your computer.0580

Now, this is a Windows path, because we are running a Windows server.0593

We are going to talk in a little bit about a sendmail program that is provided by XAMPP, so that you can mimic the sendmail program in Linux.0598

But typically, this is going to be set to a UNIX path, and it is going to be set to wherever your sendmail binary is located at.0606

Let me just go ahead and comment this back out and save.0615

One of the things that often happens is: your outgoing mail server, your SMTP server, often requires authentication.0623

And that is because, if it didn't require authentication, it is considered an open relay, they call it.0633

Spammers would take advantage of it and just send email requests to it, and they could use that server to send out email0640

as much as they wanted to, to different places.0646

So, typically, your SMTP server, like the one provided by your local cable provider,0649

is going to require some sort of authentication, so it knows that you are allowed to send emails from that server.0656

It can be done in a couple of different ways.0662

One common thing is to use a username and password that your ISP provider will give you.0664

Another thing that can be used in combination with the username and password, or on its own, is: your ISP will require that0672

any emails sent using their SMTP server, their local outgoing mail server, be originated from a computer that is on the same local network as the mail server.0681

So, for example, if you have a cable Internet service, you have to be logged onto your computer at home,0693

that is accessing the Internet through your cable modem, in order to use, for example, your local SMTP server.0702

If you try to access it elsewhere, it may not authenticate you.0708

In a Windows environment, we can use the smtp directive; and the Windows environment is what we are developing in, in this course.0714

And if that doesn't work, because authentication is required (a username and password is required), there is a program0721

that I mentioned, called fake sendmail for Windows, that is provided with XAMPP.0730

What it does is: it gives you a few more options for being able to connect to your local SMTP server, allowing you to provide authentication.0736

As mentioned, the program is called fake sendmail for Windows, and it is located in...there is a directory in your XAMPP installation0750

called sendmail, and that contains...it is called sendmail.exe, which is this program here.0760

And the feature that it adds onto the base functionality that PHP provides through php.ini, which just lets you provide0768

a basic SMTP server through the smtp directive, and doesn't allow for any authentication...fake sendmail has an add-on feature0777

that allows you to be able to specify a username and password to your SMTP server, so that, for those of you whose ISP's require you0788

to do authentication before sending an email--it is going to give you the ability to do that.0799

The username and password that you provide to your SMTP server gets configured in a file called sendmail.ini,0805

which is in the sendmail directory of the XAMPP installation.0816

That configuration file is how you specify to this fake sendmail program how you are supposed to connect to your SMTP server.0819

What that does is: you specify the name of the server (for example, smtp.roadrunner.com or .net).0829

And then, you provide your username and password your ISP provider is giving you, in order to authenticate yourself to that server.0836

Let's take a look at how this fake sendmail program changes things when we are working with XAMPP for Windows.0848

As you can see, in this diagram, we have our mail server back, and then we also have fake sendmail in the diagram, as well.0858

And so, the way using the fake sendmail program works is kind of a hybrid approach to sending email in a Windows environment.0867

You have your email client (in this case, PHP), and instead of sending an email directly to the mail server0875

by the smtp configuration directive in php.ini, it sends it to a fake sendmail program.0884

It is configured with the sendmail_path; so even though we are not using the UNIX computer, we configure the sendmail_path directive.0892

And as we saw in the php.ini file, XAMPP goes ahead and, when you have configured XAMPP...it set the sendmail_path directive0899

for you to point to this fake sendmail program.0911

And what you do is: you turn that directive on, and so when PHP goes to send a message, it sends a message to the fake sendmail.0913

And then, what sendmail does--it is not an actual SMTP server; it is not an outgoing mail server, like the real sendmail is--what it does is:0924

it goes ahead and still uses the local outgoing mail server on your network.0936

But what it does is: it allows you to configure it, so that it can provide a username and password, so it can authenticate.0942

It sends it out to your mail server by SMTP, using authentication.0950

And then, everything goes as normal from there; your local mail server sends it by SMTP0967

through the Internet, over to your recipient client on the other side.0975

If we go and take a look at the sendmail.ini file, which is the fake sendmail configuration file, we can see, it has a number of directives in it.0980

It is formatted very similar to php.ini.0991

The main directive you are going to use is smtp_server, which corresponds to the smtp directive in php.ini.0995

That is going to be the name of your ISP's outgoing mail server; so again, it could be like smtp.roadrunner.com.1003

And then, it has a couple of other configuration directives that you can do.1015

You can set (and this is going to be helpful--we are going to use this when we show an example of sending an email) error logs1020

and debug logs, and they provide you information, if you are having trouble configuring the sendmail.exe, the fake sendmail, to work.1031

That is going to be useful to you, if you are having problems.1039

Then down here (and this is sort of the key difference), there is an auth_username and an auth_password directive,1042

which is going to allow you to enter whatever username and password your ISP provided to you to use to authenticate yourself to the SMTP server.1048

So, for example, the username could be your email address; you could say, "My email address is [email protected],1062

and my password is" I wouldn't do something like this, but it would be "password."1067

And so, that is going to configure sendmail, so that when PHP goes ahead and tries to send an email,1073

it is going to run this fake sendmail program, which is going to read this sendmail.ini configuration file.1081

It is going to be able to gather your username and password to authenticate itself to your local SMTP server,1087

specified up here, and then send the email that way.1096

Let me just go ahead and put these back.1100

So now, let's talk about the mail function, which is the function built into PHP that allows you to send email.1121

It is what gets configured through php.ini, as we had talked about.1127

It has three required arguments: you have to have a to email address; you have to provide a subject; and you have to provide a message.1133

It also has two optional arguments, and it also returns a boolean value1141

indicating whether the email was successfully passed on to the mail server for delivery.1149

We are going to talk a little more about that, because, just because the mail function returns true,1155

indicating that your email message was delivered to the mail server, it doesn't necessarily mean the email is going to be properly delivered.1160

There may be problems on the mail server, such as if you have an incorrect email address or something like that.1168

So, you have to kind of be careful of that; we are going to talk about some different cases where the mail function1174

will return true, even though your email doesn't actually get sent.1181

Now, one important thing to note is that the first optional argument, which, if you look at the PHP documentation for mail--1185

the mail function--is called additional_headers, and it is an optional argument, but it is typically almost always required.1193

And what the argument is, is a string where you can pass email headers, like From, CC, BCC, and so forth.1202

Now, in order to send an email, you have to have a from email address specified.1213

So, even though there is no from argument in mail, what you have to do is specify a from header--1218

create a string that contains a from header that has the form right here--it has From: and then the email address you are sending it from.1228

You have to create that as a string, and add that as a fourth argument to the mail function.1237

An example of using the mail function: we have your to email address as the first argument.1242

You have some sample subject text; you have the content of your email message.1248

And then, this optional, but pretty much required, parameter is the additional_headers parameter.1254

And here we have provided the header From: and we provided a from email address.1263

Let's go and take a look at one of our scripts that we have created to show this.1269

First of all, let's look at mail.php, which is a script we have created to demonstrate just the basic mail functionality.1277

What we have done is: we have hard-coded a couple of different values.1288

We have hard-coded a to email address, a subject, and a test message.1291

We have also created email headers, which holds this required From: header that has the from email address.1297

And then, we make a call to the mail function, including the to email address, the subject, the message, and then this email header.1308

And then, what happens is: we output a message saying whether the email was sent successfully, or there was an error.1317

What happens is: when we run the mail function, as mentioned, it returns a boolean value that gets stored in the variable sent.1323

And so, we can test sent down here: if it's true, the email was sent successfully; if not, there was an error.1329

But as mentioned before, it doesn't necessarily mean the email is actually going to be delivered.1335

It just means it was successfully passed along to the mail server.1338

If we go and try to run this page, everything is hard-coded; it is just going to go ahead and try and send out an email.1343

And if we go ahead and load the page, you can see, we get an error.1349

And it is saying "failed to connect to mail server at localhost; verify your "SMTP" and "smtp_port" configuration directives in php.ini are set properly."1356

And we also get our own error message.1366

That is saying that our mail is not configured properly, so what we are going to do now is go ahead and walk through the process1369

of configuring php.ini and sendmail.ini, so that we can send emails from our PHP scripts.1376

Now, we are going to be using the fake sendmail program, because the mail server that we use at Educator.com requires SMTP authentication.1385

And so, using sendmail is going to allow us to provide a username and password to authenticate ourselves.1395

If we go to php.ini, we are going to comment out the smtp directive, because we are not going to be having PHP try and connect to the local SMTP server.1400

We are going to have it use the fake sendmail program.1414

So, we uncomment this sendmail_path directive, which, when you set up XAMPP, is automatically configured to point to the fake sendmail program.1416

And then, if we go into our sendmail.ini folder, we are going to enter the SMTP server we use at Educator.com, which is called mail.educator.com.1428

We are going to go ahead and turn on the error log file and the debug log file, because those will be useful to us in a bit.1444

And then, we are going to go ahead and enter our SMTP username and password that we need for authentication.1451

Now, the username we use is [email protected]; that is our email address.1457

And then, our password...I am going to do it off the screen here...is what we need to authenticate with.1464

Now, because we have changed our php.ini file, we need to restart Apache, as we always do any time we make changes.1478

So, I'm going to stop it and restart it.1489

And if we go and reload the page, we should see that our email was sent successfully.1493

What happened is: this time, when we ran it, when we called the mail function, PHP looked at the php.ini configuration file.1506

It saw that we are using a sendmail binary to send our email to the local SMTP server, and then it went ahead and invoked that.1514

It read the sendmail.ini configuration file to get our username and password to be able to send it to the server.1527

So, if we go and look at our local instance of Mozilla, the Mozilla email client is running, and we can see that we just received the email from our web page.1533

It says mail function test; and I'll just turn the headers off.1547

And so, it confirms that our email function has worked.1553

One thing to note is: if we go back to our mail page, typically, you actually prepend the mail function with the error control operator,1562

because if an error gets generated, you get this sort of ugly warning message, as we had seen earlier.1575

I'm going to go ahead and do that here, and then we're going to create an error message that is going to get1583

this PHP errorMsg variable that we talked about when we learned about the error control operator.1591

And then, if we have an error, it is going to output it down here.1598

And so, just to show how that works, I am going to go back to our php.ini file, and just temporarily get rid of the sendmail.1601

I'll just use localhost.com and make up some SMTP server that shouldn't work.1621

If we restart our Apache, and we reload the page...it's taking a little while, and that is probably because we have messed up the configuration.1627

You can see that we have gone ahead and seen that there was an error sending the email.1658

But we didn't get that ugly warning message, because we used the error suppression operator.1665

We'll go back and look at mail.php; we can see how that worked.1670

One other example page that we have created is called emailForm.php.1683

What this is: it is sort of an expansion on what we have just learned; it is a way to...instead of hard-coding an email into our system,1690

it's going to allow us to specify an email address, a subject, and a message, and actually send the email out.1699

And before I do that, let me go ahead and correct the configuration again on php.ini and restart the mail server.1706

And I am going to go ahead and run that mail.php page again, to confirm that our email functionality is working again.1719

"Email was sent successfully," and if I go and look at my inbox, I can see that it was sent; so, the email is back, working again.1731

The way the email form works is: you enter a return address email, or a "from" email (and this is something a customer could do on your website).1739

I'm just going to create a test subject, test email comments...1749

And if we click Send Email, it is going to be using the same process,1759

except it is going to be using the data we provided here, to go ahead and send the email.1763

If I go and look at my inbox, we can see an email created; it has Test subject as the subject, which is what I provided.1767

And it has From: [email protected], which is what I provided in the form, and then also the comments that I provided in the message part of the form.1779

So, if we go and look at emailForm.php, when we take a look at it, it takes two GET variables.1790

It has an action variable, and then it also has a contactInfo variable.1800

And what happens is: when you go to that page originally, no action variable is provided, and so what it does is: it loads the form that we saw.1804

The form has three different fields in it that all populate a contactInfo associative array.1814

Here, they populate it with the keys from, subject, and message.1820

And then, when we submit the form, we go ahead and submit it with the hidden field, called action, that says send email.1825

And the form, if you notice, submits to itself, emailForm.php.1831

So, when the form reloads, it is going to come down here and test to see what HTML output...1837

It is going to say, "If action is null, or if action is not equal to sendmail, output the form."1842

Well, because the action is going to be set to sendEmail now, it is going to go down here,1847

and it is going to process the information that we submitted, and send out the email.1851

As you can see, we have hard-coded the to email address, because we want to send it to the admin, for example, on this website,1857

which is just going to be our [email protected] email address we have set up.1865

And then, it pulls the from, subject, and email message from the contactInfo variable that was provided by a GET.1869

We go ahead and add the From: header, which is necessary to send the email.1876

And then, go ahead and run the mail function, and use the error suppression operator so we don't get an ugly warning message.1880

And then, we output an error message if an error occurred, and if not, we output that the email was done successfully.1887

And as we saw when we submitted the form, it is currently working; and so, everything works as expected.1894

So now, we are going to talk about updating the web application.1905

Now that we have learned about how to configure email to work in our PHP setup,1907

and we have learned about how to use the mail function, we are going to add...1912

we are going to call it a contactUs page...to our web store application.1916

What that is going to do is: that is going to allow a customer to go ahead and send some comments to the store administrator by email,1921

saying maybe they like this or that about the store.1929

It is an example of a way, if you were to have your own website, you could have people submit information or comments to you.1931

It is going to make use of the mail function, and we are going to make use of some email-related constants that we are going to add to config.php.1938

We are going to be creating contactUs.php; we are going to be editing the config file,1948

because we are going to be adding some constants, which you will see in a minute.1954

We are also going to edit the footer, and that is because1956

we are going to add a link to the contactUs page at the bottom of all of our pages.1959

And then, we are not going to talk about it, but there are some modifications that are going to occur to store.css that format the contactUs form.1964

Really quickly, to talk about the new page, contactUs.php: similar to the example we have just gone over,1973

it is going to take two GET input parameters: one is going to be called action, and one is going to be called contactInfo.1980

And action, as before, is going to determine whether the page is just going to show the form to the user1988

that allows them to enter their comments, or whether it is actually going to1992

process the comments that they submitted by a GET and actually send out the email.1995

What we are going to do is: we are going to use the value contactUs;2002

we are going to set the value action equal to contactUs when we want it to process the email.2005

So, when we have a user submit the form, we are going to submit the hidden input field, as well, that is called action.2010

And it is going to be set to the value contactUs, so that when the page reloads, it is going to know that,2016

instead of outputting the form, it is supposed to go ahead and try and send the email.2023

contactInfo is an associative array that contains the information the customer submits on the Contact Us form.2028

It is going to contain their name, their email address, and whatever comments they submitted.2036

And we are also going to have it so that the form validates contactInfo, just to make sure that all three of these fields...2044

We are going to require that all three of these fields be provided.2051

And just so you know, the default action for the page is just to display the Contact Us form.2055

That is if no action is specified to the form, or you specify an action that isn't the value contactUs.2060

The default action is to always just go ahead and display the Contact Us form.2067

Let's go take a look at what the form looks like.2071

If we look at the web application--this is the new version, 9.0, we can look at...2075

Well, first, let's go to store.php; and we can see, there has been a link added to the bottom of all the pages,2080

because we just added a link to footer.html.2087

And if we go and take a quick look at that, you can see, we just added one more link to the bottom here.2091

And when we click on that Contact Us link, it is going to take us to contactUs.php.2099

This is what the form looks like: it has a place where a customer can enter their name, their email address, and their comments.2103

And so, I'll go ahead and enter my name, my email address, and then some comments about the store.2110

And click on the Contact Us button; it is going to go ahead and send an email to a preconfigured address, which we have set up in config.php.2126

So, the email was sent successfully; it says "Thank you for your comments."2139

Actually, since I have my email client running, we can go in and look at it; and because the preconfigured email that it gets sent to2142

is our [email protected] email, we can see that it sent an email, and it said "Matthew Machaj had some comments for the store."2148

And then, it output my comments that I had submitted on the form.2156

Let's go and take a look at the code that does this.2160

First of all, let's take a look at config.php; and in config.php, we have gone ahead and added two constants.2164

We have added one called ADMIN_EMAIL_TO, and what that is: any time a user submits comments on the Contact Us form,2173

it is going to get sent to this email address; because we always want it sent to the same spot, we set it up as a constant.2183

And in this case, we are calling it ADMIN_EMAIL_TO.2188

Additionally, we always want our administrator, when they look up their comments received from the store in their email client--2192

we want to have the same subject line, so that they can identify where they are coming from.2200

And so, we have created a constant for that called CONTACT_US_EMAIL_SUBJECT.2205

It just says "Educator Store comments," which lets the administrator know that somebody submitted comments from the Educator store.2210

Now, the contactUs.php page--at the top, it processes the two GET variables that it can use.2218

One is action, and one is contactInfo, as we had talked about.2229

And then, in the data processing section, if the action is set to contactUs, which means the user submitted the form,2234

it goes ahead and just checks to make sure all of the fields on the form were not empty.2240

And if so, it goes ahead and will output the appropriate page title;2246

if not, it's going to output an error message saying "You must complete all fields to use this form."2250

So, for example, if we go back, and we leave out comments, it is going to give you the error message,2255

saying, "You need to complete all the fields on the form."2265

This is error processing, as we had seen before.2271

And then, on the output section, we output a common title, so the page is always going to say Contact Us.2274

If no error has occurred, and the action has not been specified, or it is not equal to contactUs,2279

then we are saying, "OK, go ahead and output the Contact Us email form," and the Contact Us form submits its GET data to itself.2286

It uses the contactInfo associative array, and then, it also defines, as a hidden GET variable, action with contactUs.2295

So, when the form is submitted, you will know how to process the contactUs information.2307

Also know that it is not supposed to output the form, but in this part down here, it is actually going to say,2312

if the action equals contactUs, it is going to go ahead and send the email.2318

And in this case, we can see, we created some short variables for the customer's name, the email, the comments they submitted...2323

which loads information from the contactUs GET variable.2330

What it does is: we then go ahead and build up an email message, which you saw in the email program we had.2336

And what it does is set it up so that it outputs the person's name.2342

It said, "So-and-so had some comments on the store," and then we add to that this email message, the comments that were provided.2345

And by default, it is going to send the email in plain text; so here, we are using new lines, as opposed to breaks, to format the email how we want.2356

We create the email header, and in this case, instead of having it hard-coded,2365

we use the email address provided by the customer and set the header that way.2370

And then, here, we go ahead and call the mail function.2376

And as you can see, we have used the two constants we created in config.php.2379

For the to address, we have set it equal to the ADMIN_EMAIL_TO constant, so it is always going to send it to our administrator email account.2383

It is always going to have the subject specified by the CONTACT_US_EMAIL_SUBJECT constant.2390

Here, we have included the message that we built up, up here, which has the customer's name and their comments.2397

And then, we have also added the email headers variable, which has the From: header for the email message.2402

Down here, if this is successful (and here we use the error suppression operator again), it outputs a Thank You message.2410

If not, it says "There was an error in sending your comments."2417

And so, that is how the Contact Us page works.2422

One thing you might note is that (and this is kind of related, but it's a commenting thing) is: sometimes, you will see that,2424

at the end of if statements, for example, we have if action equals null, or action is not equal to contactUs,2433

when you are getting ready to enter another elseif statement, you can add a comment to the end,2440

on the same line as the curly brace of the if statement, saying the test condition that was used to enter that.2446

So, down here, we know that the section up here was entered if action was equal to null or if action was not equal to contactUs.2452

Similarly, at the bottom of this elseif statement, we can, at the end of the code, add a comment saying,2460

"OK, this section was entered from action=contactUs."2467

That is just a way to provide some feedback to you, as far as comments go, within your script, to make it a little bit easier to read,2469

because when you have long elseif and if statements, like this, you might not know exactly what the test condition was2477

that had you enter that; and so, this just adds a little more information to that.2485

So now, I just want to quickly talk about the homework challenge we are going to have for this course.2494

I would like you to go ahead and try and set up your XAMPP configuration, so that you can send email from your PHP scripts.2497

And you may just be able to edit the php.ini file; just edit that smtp directive.2504

Maybe your local SMTP server doesn't require authentication, or it does require authentication, but it doesn't require using your password;2510

it just requires that you send the email from a computer on your network.2517

So, I would suggest going ahead and trying just setting that first.2522

You will need to contact your ISP to find out what the domain name of your SMTP or outgoing mail server is.2525

Alternatively, you may have to use the fake sendmail program, if your outgoing or SMTP mail server requires authentication.2532

And what you can do there is: as we had gone over, you can edit sendmail.ini2541

in order to add your username and password, so that you can perform authentication.2546

You also are going to need to change, in php.ini (not to forget)--you need to enable the sendmail_path directive,2551

which is going to tell PHP to use the fake sendmail program.2558

Once you have done that, just go ahead and set up a sample script that is going to call the mail function with some hard-coded values,2562

making sure to include the From: header as that fourth argument to the mail function.2569

And just do that in order to test the configuration; go ahead and try sending an email,2574

and then make sure that you can see it in your email client, that it is actually being sent, just to verify the configuration.2578

Once you have done that, just create a script, similar to what we did in the course today,2587

that contains a form where a user can put their email address, a subject, and a message.2592

And, using an action GET parameter, have the script submit the form to itself;2597

and based on the action that says something like contactUs or sendEmail,2604

have the email be generated, using the information that the user provided in the form, and have it send out the email.2609

Be sure to test to verify that the mail function worked and was successful.2616

And then, also check in your email client to make sure that the email was delivered.2621

That ends today's lesson; thank you for watching Educator.com--I look forward to seeing you next time.2625

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.