How to send email using PHP mail() function

Here’s a quick way to send an email. You only need one line for that. I always use this script to send an alert on any event triggered. Let say somebody just make a payment on your site.

$headers = "From: sendername <sender@example.com>\r\n";
$headers .= 'Cc: cc@example.com' . "\r\n";
$headers .= 'Bcc: bcc@example.com' . "\r\n";
$headers .= "Reply-To: sender@example.com\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
mail('recipient@example.com','Subject','Message',$headers);

For the “from” email, some hosting requires you to use only registered email address in your hosting/domain.

Leave a Reply

Your email address will not be published. Required fields are marked *