In the article How to send a simple email from a php script we have seen how to send a simple email using a php script.

This is useful but sometimes you could prefer to send html formatted email, especially if you are sending automated messages like a subscription confirmation, for example those messages you receive when you have subscribed a service and then on this email you have to click a link to confirm your subscription.

It’s not very professional sending a plain text message the user has to copy and paste the confirmation link into the browser instead of clicking on an hyperlink.


        $to          = “username@mailservice.domain”;

        $verify_link = “$to;

        $subject     = ‘Please confirm your subscription’;

        $message     = “<html> 

  <body bgcolor=\”#DCEEFC\”> 

        Dear <strong>$username</strong>,<br>

        Welcome and thank you very much for joining our community!<br>

        To finish the process and activate your account, please click the following URL:


        <a href=\”$verify_link\”>subscribe</a>




        $headers = ‘From: Community – enjoy our community <>’ . “\r\n” .

        ‘X-Mailer: PHP/’ . phpversion() . “\r\n”;

        $headers .= “MIME-Version: 1.0\r\n”; 

        $headers .= “Content-Type: text/html; charset=ISO-8859-1\r\n”; 

        mail($to, $subject, $message, $headers);



That’s all, now you only have to parametrize the script for your needs,