How to email with PHP
Friday, July 11th, 2008Sending 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 <sender@example.com>\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”;$MESSAGE=”
Hello there,This is a test message.
From Admin.”;
mail(”recipient@domain.com”, “Example Subject”, $MESSAGE, $EMAIL_HEADER);
The above code will send out an email to recipient@domain.com with subject “Example Subject” and the message stored in $MESSAGE variable.
The $EMAIL_HEADER determines that this email will be sent from Sender Name <sender@example.com> and is high priority.