SlideShare ist ein Scribd-Unternehmen logo
1 von 32
PHP HYPERTEXT PREPROCESSOR
[object Object]
PHP COMMANDS
EMAIL WITH PHP  CONTENTS
INTRODUCTION
PHP stands for Hypertext Preprocessor and is a server-side language. This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becoming one of the most popular scripting languages on the INTERNET. INTRODUCTION
WRITING PHP Writing PHP on your computer is actually very simple. You don't need any special software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.
DECLARING PHP PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows: <? PHP Code In Here ?>
PHP COMMANDS
To output text in your PHP script is actually very simple. . The main one you will be using, though, is print. Print will allow you to output text, variables or a combination of the two so that they display on the screen. EXAMPLE: <? print(&quot;Hello world!&quot;); ?> Which will display: Hello world! on the screen. PRINTING TEXT
VARIABLES As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code: $welcome_text = &quot;Hello and welcome to my website.&quot;; This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string.
OUTPUTING VARIABLES To display a variable on the screen uses exactly the same code as to display text but in a slightly different form. The following code would display your welcome text: <? $welcome_text = &quot;Hello and welcome to my website.&quot;; print($welcome_text); ?>
FORMATTING THE TEXT Formatting the text in PHP includes the color in codes and not in namesFor this example I will change the text to the Arial font in red. The normal code for this would be: <font face=&quot;Arial&quot; color=&quot;#FF0000&quot;></font>  You can now include this in your print statement: print(&quot;<font face=amp;quot;Arialamp;quot; coloramp;quot;#FF0000amp;quot;>Hello and welcome to my website.</font>&quot;); which will make the browser display: Hello and welcome to my website.
If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically it checks the condition. If it is true, the then statement is executed. If not, the else statement is executed. The structure of an IF statement is as follows: IF (something == something else) {THEN Statement } else { ELSE Statement} THE BASIC IF STRUCTURE
VARIABLES IN IF STATEMENT The most common use of an IF statement is to compare a variable to another piece of text, a number, or another variable. For example: if ($username == &quot;webmaster&quot;) which would compare the contents of the variable to the text string. The THEN section of code will only be executed if the variable is exactly the same as the contents of the quotation marks so if the variable contained 'Web master' or 'WEBMASTER' it will be false.
CONSTRUCTING THEN  To add to your script, you can now add a THEN statement: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;;} This will only display this text if the username is webmaster. If not, nothing will be displayed. You can actually leave an IF statement like this, as there is no actual requirement to have an ELSE part. This is especially useful if you are using multiple IF statements.
CONSTRUCTING ELSE Adding The ELSE statement is as easy as the THEN statement. Just add some extra code: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;; } else { echo &quot;We are sorry but you are not a recognized user&quot;;} Of course, you are not limited to just one line of code. You can add any PHP commands in between the curly brackets. You can even include other IF statements (nested statements).
The for loop is simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are: ,[object Object]
Check to see if the conditional statement is true.
Execute the code within the loop.
Increment a counter at the end of each iteration through the loop. Syntax: for (init; condition; increment) { code to be executed;} FOR LOOP
WHILE STATEMENT If you have a piece of code which you want to repeat several times without retyping it, you can use a while loop. For instance if you wanted to print out the words &quot;Hello World&quot; 5 times you could use the following code: $times = 5; $x = 0; while ($x < $times) { echo &quot;Hello World&quot;; ++$x;}
USING $X The variable counting the number of repeats ($x in the above example) can be used for much more than just counting. For example if you wanted to create a web page with all the numbers from 1 to 1000 on it, you could either type out every single one or you could use the following code: $number = 1000; $current = 0; while ($current < $number) { ++$current; echo &quot;$current<br>&quot;;}
ARRAY Arrays are common to many programing languages. They are special variables which can hold more than one value, each stored in its own numbered 'space' in the array. Arrays are extremely useful, especially when using WHILE loops.
TYPES OF ARRAY In PHP, there are three kind of arrays: * Numeric array - An array with a numeric index * Associative array - An array where each ID key is associated with a value * Multidimensional array - An array containing one or more arrays
SETTING UP AN ARRAY Setting up an array is slightly different to setting up a normal variable. In this example I will set up an array with 5 names in it: $names[0] = 'John'; $names[1] = 'Paul'; $names[2] = 'Steven'; As you can see, the parts of an array are all numbered, starting from 0. To add a value to an array you must specify the location in the array by putting a number in [ ].
PHP WITH FORMS Setting up a form for use with a PHP script is exactly the same as normal in HTML. As this is a PHP tutorial I will not go into depth in how to write your form but I will show you three of the main pieces of code you must know: <input type=&quot;text&quot; name=&quot;the box&quot; value=&quot;Your Name&quot;> Will display a text input box with Your Name written in it as default. The value section of this code is optional. The information defined by name will be the name of this text box and should be unique. <textarea name=&quot;message&quot;> Please write your message here. </textarea> Will display a large scrolling text box with the text 'Please write your message here.' as default. Again, the name is defined and should be unique. <input type=&quot;submit&quot; value=&quot;Submit&quot;> This will create a submit button for your form. You can change what it says on the button by changing the button's value.
GET METHOD  The built-in $_GET function is used to collect values from a form sent with method=&quot;get&quot;. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters). Example <form action=&quot;welcome.php&quot; method=&quot;get&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL sent to the server could look something like this: http://www.w3schools.com/welcome.php?fname=Peter&age=37 The &quot;welcome.php&quot; file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome <?php echo $_GET[&quot;fname&quot;]; ?>.<br /> You are <?php echo $_GET[&quot;age&quot;]; ?> years old!
POST METHOD The built-in $_POST function is used to collect values from a form sent with method=&quot;post&quot;.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.Example <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL will look like this: http://www.w3schools.com/welcome.php The &quot;welcome.php&quot; file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old.
READING FROM AN ARRAY Reading from an array is just the same as putting information in. All you have to do is to refer to the array and the number of the piece of data in the array. So if I wanted to print out the third name I could use the code: echo &quot;The third name is $names[2]&quot;; Which would output: The third name is Steven
PHP FUNCTIONS In PHP, there are more than 700 built-in functions.  This chapter shows how to create your own functions. A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax: function functionName() { code to be executed; }
E-MAIL WITH PHP

Weitere ähnliche Inhalte

Was ist angesagt? (20)

DJango
DJangoDJango
DJango
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Java 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional InterfacesJava 8 Lambda Built-in Functional Interfaces
Java 8 Lambda Built-in Functional Interfaces
 
PHP
PHPPHP
PHP
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
CSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, LinzCSS Grid Layout for Topconf, Linz
CSS Grid Layout for Topconf, Linz
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php
PhpPhp
Php
 
Django
DjangoDjango
Django
 
Php with MYSQL Database
Php with MYSQL DatabasePhp with MYSQL Database
Php with MYSQL Database
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
php
phpphp
php
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
PUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBootPUC SE Day 2019 - SpringBoot
PUC SE Day 2019 - SpringBoot
 
Php
PhpPhp
Php
 
Json
JsonJson
Json
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 

Andere mochten auch

La participación ciudadana
La participación ciudadanaLa participación ciudadana
La participación ciudadanaOMAIDA Y ANYI
 
Practica 2 sistemas numericos y packet tracer
Practica 2 sistemas numericos y packet tracerPractica 2 sistemas numericos y packet tracer
Practica 2 sistemas numericos y packet tracerArana Paker
 
Introduccion a las redes
Introduccion a las redesIntroduccion a las redes
Introduccion a las redesNoraTibaduiza
 
Actividades de aprendizaje 4
Actividades de aprendizaje 4Actividades de aprendizaje 4
Actividades de aprendizaje 4Yair Hernandez
 
Formulario requerimiento siti crm
Formulario requerimiento siti  crmFormulario requerimiento siti  crm
Formulario requerimiento siti crmgrupo nkjr
 
Desenvolvimento e igualdade
Desenvolvimento e igualdadeDesenvolvimento e igualdade
Desenvolvimento e igualdadeCésar Pereira
 
La falta de una plataforma virtual en la[1]
La falta de una plataforma virtual en la[1]La falta de una plataforma virtual en la[1]
La falta de una plataforma virtual en la[1]lidaleon
 
Sintesis informativa 17 de marzo 2015
Sintesis informativa 17 de marzo 2015Sintesis informativa 17 de marzo 2015
Sintesis informativa 17 de marzo 2015megaradioexpress
 
Presentación taller 3
Presentación taller 3Presentación taller 3
Presentación taller 3Juan Gonzalez
 
Administración de empresas info sergio (1)
Administración de empresas info sergio (1)Administración de empresas info sergio (1)
Administración de empresas info sergio (1)6561971604
 
Breaking up with "Engagement"
Breaking up with "Engagement"Breaking up with "Engagement"
Breaking up with "Engagement"Dena Walker
 

Andere mochten auch (20)

Competencias Laborales
Competencias LaboralesCompetencias Laborales
Competencias Laborales
 
La participación ciudadana
La participación ciudadanaLa participación ciudadana
La participación ciudadana
 
Practica 2 sistemas numericos y packet tracer
Practica 2 sistemas numericos y packet tracerPractica 2 sistemas numericos y packet tracer
Practica 2 sistemas numericos y packet tracer
 
Introduccion a las redes
Introduccion a las redesIntroduccion a las redes
Introduccion a las redes
 
Actividades de aprendizaje 4
Actividades de aprendizaje 4Actividades de aprendizaje 4
Actividades de aprendizaje 4
 
Mapa mental
Mapa mentalMapa mental
Mapa mental
 
Formulario requerimiento siti crm
Formulario requerimiento siti  crmFormulario requerimiento siti  crm
Formulario requerimiento siti crm
 
Desenvolvimento e igualdade
Desenvolvimento e igualdadeDesenvolvimento e igualdade
Desenvolvimento e igualdade
 
Webny (2014)
Webny (2014)Webny (2014)
Webny (2014)
 
La falta de una plataforma virtual en la[1]
La falta de una plataforma virtual en la[1]La falta de una plataforma virtual en la[1]
La falta de una plataforma virtual en la[1]
 
Poderes
PoderesPoderes
Poderes
 
Sintesis informativa 17 de marzo 2015
Sintesis informativa 17 de marzo 2015Sintesis informativa 17 de marzo 2015
Sintesis informativa 17 de marzo 2015
 
Tema 1 el estado1
Tema 1 el estado1Tema 1 el estado1
Tema 1 el estado1
 
Presentación taller 3
Presentación taller 3Presentación taller 3
Presentación taller 3
 
Plataformas educativas
Plataformas educativasPlataformas educativas
Plataformas educativas
 
Administración de empresas info sergio (1)
Administración de empresas info sergio (1)Administración de empresas info sergio (1)
Administración de empresas info sergio (1)
 
Extintores
ExtintoresExtintores
Extintores
 
Universidad fermín toro
Universidad fermín toroUniversidad fermín toro
Universidad fermín toro
 
Breaking up with "Engagement"
Breaking up with "Engagement"Breaking up with "Engagement"
Breaking up with "Engagement"
 
Redes ,,,,
Redes ,,,,Redes ,,,,
Redes ,,,,
 

Ähnlich wie Php (20)

Web development
Web developmentWeb development
Web development
 
PHP Tutorials
PHP TutorialsPHP Tutorials
PHP Tutorials
 
PHP MySQL
PHP MySQLPHP MySQL
PHP MySQL
 
Open Source Package PHP & MySQL
Open Source Package PHP & MySQLOpen Source Package PHP & MySQL
Open Source Package PHP & MySQL
 
Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9Open Source Package Php Mysql 1228203701094763 9
Open Source Package Php Mysql 1228203701094763 9
 
What Is Php
What Is PhpWhat Is Php
What Is Php
 
Php
PhpPhp
Php
 
Php Learning show
Php Learning showPhp Learning show
Php Learning show
 
Php Crash Course
Php Crash CoursePhp Crash Course
Php Crash Course
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0Dynamic Web Pages Ch 1 V1.0
Dynamic Web Pages Ch 1 V1.0
 
John Rowley Notes
John Rowley NotesJohn Rowley Notes
John Rowley Notes
 
Learn php with PSK
Learn php with PSKLearn php with PSK
Learn php with PSK
 
Php
PhpPhp
Php
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php by shivitomer
Php by shivitomerPhp by shivitomer
Php by shivitomer
 
Php essentials
Php essentialsPhp essentials
Php essentials
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 
Php
PhpPhp
Php
 

Php

  • 2.
  • 4. EMAIL WITH PHP CONTENTS
  • 6. PHP stands for Hypertext Preprocessor and is a server-side language. This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becoming one of the most popular scripting languages on the INTERNET. INTRODUCTION
  • 7. WRITING PHP Writing PHP on your computer is actually very simple. You don't need any special software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.
  • 8. DECLARING PHP PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows: <? PHP Code In Here ?>
  • 10. To output text in your PHP script is actually very simple. . The main one you will be using, though, is print. Print will allow you to output text, variables or a combination of the two so that they display on the screen. EXAMPLE: <? print(&quot;Hello world!&quot;); ?> Which will display: Hello world! on the screen. PRINTING TEXT
  • 11. VARIABLES As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code: $welcome_text = &quot;Hello and welcome to my website.&quot;; This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string.
  • 12. OUTPUTING VARIABLES To display a variable on the screen uses exactly the same code as to display text but in a slightly different form. The following code would display your welcome text: <? $welcome_text = &quot;Hello and welcome to my website.&quot;; print($welcome_text); ?>
  • 13. FORMATTING THE TEXT Formatting the text in PHP includes the color in codes and not in namesFor this example I will change the text to the Arial font in red. The normal code for this would be: <font face=&quot;Arial&quot; color=&quot;#FF0000&quot;></font> You can now include this in your print statement: print(&quot;<font face=amp;quot;Arialamp;quot; coloramp;quot;#FF0000amp;quot;>Hello and welcome to my website.</font>&quot;); which will make the browser display: Hello and welcome to my website.
  • 14. If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically it checks the condition. If it is true, the then statement is executed. If not, the else statement is executed. The structure of an IF statement is as follows: IF (something == something else) {THEN Statement } else { ELSE Statement} THE BASIC IF STRUCTURE
  • 15. VARIABLES IN IF STATEMENT The most common use of an IF statement is to compare a variable to another piece of text, a number, or another variable. For example: if ($username == &quot;webmaster&quot;) which would compare the contents of the variable to the text string. The THEN section of code will only be executed if the variable is exactly the same as the contents of the quotation marks so if the variable contained 'Web master' or 'WEBMASTER' it will be false.
  • 16. CONSTRUCTING THEN To add to your script, you can now add a THEN statement: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;;} This will only display this text if the username is webmaster. If not, nothing will be displayed. You can actually leave an IF statement like this, as there is no actual requirement to have an ELSE part. This is especially useful if you are using multiple IF statements.
  • 17. CONSTRUCTING ELSE Adding The ELSE statement is as easy as the THEN statement. Just add some extra code: if ($username == &quot;webmaster&quot;) { echo &quot;Please enter your password below&quot;; } else { echo &quot;We are sorry but you are not a recognized user&quot;;} Of course, you are not limited to just one line of code. You can add any PHP commands in between the curly brackets. You can even include other IF statements (nested statements).
  • 18.
  • 19. Check to see if the conditional statement is true.
  • 20. Execute the code within the loop.
  • 21. Increment a counter at the end of each iteration through the loop. Syntax: for (init; condition; increment) { code to be executed;} FOR LOOP
  • 22. WHILE STATEMENT If you have a piece of code which you want to repeat several times without retyping it, you can use a while loop. For instance if you wanted to print out the words &quot;Hello World&quot; 5 times you could use the following code: $times = 5; $x = 0; while ($x < $times) { echo &quot;Hello World&quot;; ++$x;}
  • 23. USING $X The variable counting the number of repeats ($x in the above example) can be used for much more than just counting. For example if you wanted to create a web page with all the numbers from 1 to 1000 on it, you could either type out every single one or you could use the following code: $number = 1000; $current = 0; while ($current < $number) { ++$current; echo &quot;$current<br>&quot;;}
  • 24. ARRAY Arrays are common to many programing languages. They are special variables which can hold more than one value, each stored in its own numbered 'space' in the array. Arrays are extremely useful, especially when using WHILE loops.
  • 25. TYPES OF ARRAY In PHP, there are three kind of arrays: * Numeric array - An array with a numeric index * Associative array - An array where each ID key is associated with a value * Multidimensional array - An array containing one or more arrays
  • 26. SETTING UP AN ARRAY Setting up an array is slightly different to setting up a normal variable. In this example I will set up an array with 5 names in it: $names[0] = 'John'; $names[1] = 'Paul'; $names[2] = 'Steven'; As you can see, the parts of an array are all numbered, starting from 0. To add a value to an array you must specify the location in the array by putting a number in [ ].
  • 27. PHP WITH FORMS Setting up a form for use with a PHP script is exactly the same as normal in HTML. As this is a PHP tutorial I will not go into depth in how to write your form but I will show you three of the main pieces of code you must know: <input type=&quot;text&quot; name=&quot;the box&quot; value=&quot;Your Name&quot;> Will display a text input box with Your Name written in it as default. The value section of this code is optional. The information defined by name will be the name of this text box and should be unique. <textarea name=&quot;message&quot;> Please write your message here. </textarea> Will display a large scrolling text box with the text 'Please write your message here.' as default. Again, the name is defined and should be unique. <input type=&quot;submit&quot; value=&quot;Submit&quot;> This will create a submit button for your form. You can change what it says on the button by changing the button's value.
  • 28. GET METHOD The built-in $_GET function is used to collect values from a form sent with method=&quot;get&quot;. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max. 100 characters). Example <form action=&quot;welcome.php&quot; method=&quot;get&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL sent to the server could look something like this: http://www.w3schools.com/welcome.php?fname=Peter&age=37 The &quot;welcome.php&quot; file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome <?php echo $_GET[&quot;fname&quot;]; ?>.<br /> You are <?php echo $_GET[&quot;age&quot;]; ?> years old!
  • 29. POST METHOD The built-in $_POST function is used to collect values from a form sent with method=&quot;post&quot;.Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.Example <form action=&quot;welcome.php&quot; method=&quot;post&quot;> Name: <input type=&quot;text&quot; name=&quot;fname&quot; /> Age: <input type=&quot;text&quot; name=&quot;age&quot; /> <input type=&quot;submit&quot; /></form> When the user clicks the &quot;Submit&quot; button, the URL will look like this: http://www.w3schools.com/welcome.php The &quot;welcome.php&quot; file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome <?php echo $_POST[&quot;fname&quot;]; ?>!<br /> You are <?php echo $_POST[&quot;age&quot;]; ?> years old.
  • 30. READING FROM AN ARRAY Reading from an array is just the same as putting information in. All you have to do is to refer to the array and the number of the piece of data in the array. So if I wanted to print out the third name I could use the code: echo &quot;The third name is $names[2]&quot;; Which would output: The third name is Steven
  • 31. PHP FUNCTIONS In PHP, there are more than 700 built-in functions. This chapter shows how to create your own functions. A function will be executed by a call to the function. You may call a function from anywhere within a page. Syntax: function functionName() { code to be executed; }
  • 33. Mail is extremely easy to send from PHP, unlike using scripting languages which require special setup (like CGI). There is actually just one command, mail() for sending mail. It is used as follows: mail($to,$subject,$body,$headers); In this example I have used variables as they have descriptive names but you could also just place text in the mail command. Firstly, $to. This variable (or section of the command) contains the e-mail address to which the mail will be sent. $subject is the section for the subject of the e-mail and $body is the actual text of the e-mail.The section $headers is used for any additional e-mail headers you may want to add. The most common use of this is for the From field of an e-mai but you can also include other headers like cc and bcc. MAIL COMMAND
  • 34. SENDING MAIL Before sending your mail, if you are using variables, you must, of course, set up the variable content beforehand. Example: $to = &quot;php@gowansnet.com&quot;; $subject = &quot;PHP Is Great&quot;; $body = &quot;PHP is one of the best scripting languages around&quot;; $headers = &quot;From: webmaster@gowansnet.com&quot;; mail($to,$subject,$body,$headers); echo &quot;Mail sent to $to&quot;; This code will acutally do two things. Firstly it will send a message to php@gowansnet.com with the subject 'PHP Is Great' and the text: PHP is one of the best scripting languages around and the e-mail will be from webmaster@gowansnet.com. It will also output the text: Mail sent to php@gowansnet.com
  • 35. ERROR CONTROL As anyone who has been scripting for a while will know, it is extremely easy to make mistakes in your code and it is also very easy to input an invalid e-mail address (especially if you are using your script for form to mail). Because of this, you can add in a small piece of code which will check if the e-mail is sent: if(mail($to,$subject,$body,$headers)) { echo &quot;An e-mail was sent to $to with the subject: $subject&quot;;} else { echo &quot;There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid&quot;;} This code is quite self explanatory If the mail is sent successfully it will output a message to the browser telling the user, if not, it will display an error message with some suggestions for correcting the problem.
  • 36. PHP INSTALLATION The Windows PHP installer is available from the downloads page at » http://www.php.net/downloads.php. This installs the CGI version of PHP and for IIS, PWS, and Xitami, it configures the web server as well. The installer does not include any extra external PHP extensions (php_*.dll) as you'll only find those in the Windows Zip Package and PECL downloads. First, install your selected HTTP (web) server on your system, and make sure that it works. Run the executable installer and follow the instructions provided by the installation wizard. Two types of installation are supported - standard, which provides sensible defaults for all the settings it can, and advanced, which asks questions as it goes along. The installation wizard gathers enough information to set up the php.ini file, and configure certain web servers to use PHP. One of the web servers the PHP installer does not configure for is Apache, so you'll need to configure it manually. Once the installation has completed, the installer will inform you if you need to restart your system, restart the server, or just start using PHP.
  • 37. PHP INI FILE Since PHP 5.3.0, PHP includes support for .htaccess-style INI files on a per-directory basis. These files are processed only by the CGI/FastCGI SAPI. This functionality obsoletes the PECL htscanner extension. If you are using Apache, use .htaccess files for the same effect. In addition to the main php.ini file, PHP scans for INI files in each directory, starting with the directory of the requested PHP file, and working its way up to the current document root (as set in $_SERVER['DOCUMENT_ROOT']). Only INI settings with the modes PHP_INI_PERDIR and PHP_INI_USER will be recognized in .user.ini-style INI files. Two new INI directives, user_ini.filename and user_ini.cache_ttl control the use of user INI files. user_ini.filename sets the name of the file PHP looks for in each directory; if set to an empty string, PHP doesn't scan at all. The default is .user.ini. user_ini.cache_ttl controls how often user INI files are re-read. The default is 300 seconds (5 minutes).