Tag Archives: email

Simple email function to send html content

Use the the below send_mail() function to send the text or html mail to specific recipients

function send_mail($to, $from, $subject, $body, $cc='', $bcc=''){
    // To send HTML mail, you can set the Content-type header.
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    //add additional headers like, reply-to, etc if you need
        $headers .= "Cc: $cc\r\n";
    $headers .= "Bcc: $bcc\r\n";
    // and now native mail function
    mail($to,$subject, $body, $headers);
   //you can use the return type for success message or error message

You can use the above function by calling the function with parameters as below

    send_mail('recipient@domain.com', 'frommail@fromdomainname.com', 'Hello subject', 'Content');