|Lessons||PHP HTTP Functions|
The header() function is used to output an HTTP header string, such as a URL redirection. The header() function has to be used before any data is sent to the browser, this also includes HTML tags. Failing to do so would result in an error. However, we can do any sort of computations or database manipulations before using this function. The following call to the header() function redirects a user to http://pickatutorial.com.
For example, to use the header() function to redirect a user to a new location, use header("Location: http://www.pickatutorial.com");
Please note the use of the exit command after a call to the header() function. This guarantees that the script stops executing immediately as it reaches the exit command.
This function is used to send a cookie to the user. All the cookies have to be sent to the user before any other data is sent to the user this also included calls to the header() function. Its syntax follows:
The PHP mail() function is used to send emails. Its syntax follows:
mail("recipient", "subject", "message", "mail headers");
For example, the following code sends mail to firstname.lastname@example.org, with a subject of "Test email" and a message body saying "This is a test email message". The From line is part of the additional mail headers.
mail("email@example.com", "Test email!",
"This is a test email message", "From: firstname.lastname@example.org\n");