Sending emails using PHP5.2
As this tutorial has no doubt shown, PHP is a powerful programming language with many powerful functions. What has still to be covered in this tutorial emphasises this further.
PHP includes a set of functions that permit sending email messages using the web server that the PHP interpreter is run from.
Sending an email using PHP
PHP provides a very simple function called
The function takes three essential parameters which themselves become hearders for the email:
<?php mail($to, $subject, $message); ?>
All of these parameters are self-explanatory.
Additional mail headers
<?php mail($to, $subject, $message, $headers); ?>
$headers variable is a string variable that specifies more headers for the email. The following table
shows some of these headers and their purpose:
|From||The email address that the email came from|
|Content-Type|| What type of content the email contains. For instance
|X-Priority||The priority level of the email. This specifies how high the email should be in terms of priority in the recipient's email inbox. Use with caution.|
|Reply-To||The address that should receive any replies.|
|Cc||Carbon-copy (CC). Send a 'carbon-copy' of the email to a recipient.|
|Bcc||Blind-carbon-copy (BCC). Send a 'carbon-copy' of the email blindly to a recipient.|
|Mime-Version||Specifies the Multipurpose Internet Mail Extension (MIME) version used with the email.|
Headers should be separated with the carriage return character (in UNIX it is
PHP can send HTML-based emails rather than the standard text based emails using the
<?php $content = "<strong>Hello world</strong>"; $headers = "MIME-Version: 1.0\rContent-Type: text/html; charset=utf-8\r" mail($to, $subject, $message, $headers); ?>