Simple function to send an email in PHP, and that actually works 😉
Just be aware that I added a Hook (check the PHP Hook class).
/**
* Simple function to send an email
*
* @param string $to
* @param string $from
* @param string $subject
* @param string $body
* @param string $extra_header
* @return boolean
*/
function email($to,$from,$subject,$body,$headers=NULL)
{
//we add hook just in case we want to overwrite the email function
//example Hook::add_action('email','some_function_used_instead_email');
if (Hook::exists_action('email'))
{
return Hook::do_action('email',func_get_args());
}
else
{
if ($headers==NULL)
{
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers.= 'Content-type: text/html; charset=utf8'. PHP_EOL;
$headers.= 'From: '.$from.PHP_EOL;
$headers.= 'Reply-To: '.$from.PHP_EOL;
$headers.= 'Return-Path: '.$from.PHP_EOL;
$headers.= 'X-Mailer: PHP/' . phpversion().PHP_EOL;
}
return mail($to,$subject,$body,$headers);
}
}