Sending mail from PHP

The php mail() function is described as follows:

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

This basically means that the first three parameters (to, subject and message) are requiered in order for the function to work. But we also have the option to send additional headers, and in it is in these additional headers that we can specify things like the “from” and “reply-to”.

For example:

$to = '';
$subject = 'the subject';
$message = 'the message';
$headers = 'From:' . "\r\n" .
    'Reply-To:' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

If you were sending HTML messages you would also use the addidional headers to specify the MIME version, Content-Type and character set.

For example:

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Someone <>, someoneelse <>' . "\r\n";
$headers .= 'From: John Smith <>' . "\r\n";
$headers .= 'Cc:' . "\r\n";
$headers .= 'Bcc:' . "\r\n";

More info on mail() check out the official documentation.