Quick Email Function
February 7th, 2008 Posted in PHPIts not the most secure email function in the world but if you want something quick or simple especially for testing then I use the below…
function send_email($recipient,$subject,$body)
{
$headers = “From: Email System\n”;
$headers .= “Reply-To: me@mydomain.com\n”;
$headers .= “MIME-version: 1.0\n”;
$headers .= “Content-type: multipart/alternative; boundary=\”Message-Boundary\”\n\n”;
$headers .= “This is a multi-part message in MIME format.\n\n”;
$headers .= “–Message-Boundary\n”;
$headers.=”Content-Type: text/plain; charset=iso-8859-1\n”;
$headers.=”Content-Transfer-Encoding: 8bit\n\n”;
$headers.= $body.”\n\n”;
$headers.=”–Message-Boundary–”;
return mail($recipient,$subject,”",$headers);
}
This will send an email given a recipient, subject, and email text and return TRUE if the sending was successful, and FALSE if the sending failed. Note that the return is not if it was received successfully, only that the mail function itself didnt find any fault.