How you can send HTML email messages with PHP

In my previous tutorial i've spoken about how you can send unlimited email messages using a simple PHP function. And now, I have created a simple PHP function which allows you and me to send HTML email messages.

And there's my function:

<?php

// connect this file to your database.
// You must have an table with this fields: ID and email

function send_to($email,$subject,$messagge,$from)
{
$header = "From:".$from;
$header .= "MIME-version: 1.0"; // this code will declare the version of the messagge body format standart
$header .= "Content-Type: text/html; charset=utf-8"; // this code allows the full richness of web pages to be available in e-mail.
mail($email,$subject,$messagge,$header); // this function will send all emails to your clients
}

$get_email = mysql_query("SELECT * FROM mytable"); // With this code I will extract all email addresses from my database.

while($email = mysql_fetch_array($get_email)):
$messagge = "<p>html message</p>"; // here you can add your html code

send_to($email,$subject,$messagge,"mymail@mail.com"); // with this code I will call my function that allows to send emails
endwhile;

You can use this function to send newsletter with customized html templates!

Video tutorial:









Leave a Comment