Archive for July, 2008

How to email with PHP

Friday, July 11th, 2008

Sending emails via PHP is rather simple with the mail() function.

mail() function has the following function prototype:

bool mail  ( string $to  , string $subject  , string $message  [, string $additional_headers  [, string $additional_parameters  ]] )

Here is an example usage:

$EMAIL_HEADER = “From: Sender Name <>\r\n”;
$EMAIL_HEADER .= “MIME-Version: 1.0\r\n”;
$EMAIL_HEADER .= “X-Priority: 1\r\n”;
$EMAIL_HEADER .= “X-MSmail-Priority: High\r\n”;

Hello there,

This is a test message.

From Admin.”;

mail(“”, “Example Subject”, $MESSAGE, $EMAIL_HEADER);

The above code will send out an email to with subject “Example Subject” and the message stored in $MESSAGE variable.

The $EMAIL_HEADER determines that this email will be sent from Sender Name <> and is high priority.