How to Send PHP Email in HTML Format?

PHP mail() is one of the useful functions you can use to send an email to one or more people. You can also use this function to send emails dynamically to people such as who submit a form or who contact you via website. Recently, I was creating a course Creating Social Network in PHP in which I used email verification for users who wanted to register on the social networking website. Since I wanted to send the email to the users in HTML format which look a lot better and professional rather than sending the plain-text email, so I did that and now I’ll exactly give you the code for sending PHP emails in HTML format.


The Simple Plain-Text Email in PHP

First of all, you should know about the basic email functionality in PHP, for example you want to send email to someone using PHP then you’ll have to use PHP mail function for it, and for that you need four parameters to be added in the email function something like this:

$to = “”;

$subject = “Verify Your Email”;

$message = “This is a message for you!”;

$from = “”;


The above four local variables hold some information and then we use the PHP mail() function to send the email, this email will only send plain data, I mean normal text, and you can’t send any HTML tags in this email, that will not work. But if you want to send a beautiful HTML & CSS formatted email then you do so. Carry on reading.

Sending PHP Email with HTML & CSS

Now here is the magic, you can use extra headers to send an email which contains HTML and CSS codes, and this will be actually applied on the page. Now below is the full code which you can straight take from here and can use in your projects, this will send the email to the user which is in the $to variable, and the email will be fully designed.

$to = “;
$subject = “Verify your email address.”;

$message = ”
Hello <strong>John Doe</strong>

<h2>We are a company here in the USA</h2>

<marquee>We do business with clients</marquee>

<h3 style=’color:read;’>We welcome you to our website</h3>

// Always set content-type when sending HTML email
$headers = “MIME-Version: 1.0” . “\r\n”;
$headers .= “Content-type:text/html;charset=UTF-8” . “\r\n”;
$headers .= ‘From: <>‘ . “\r\n”;


The above email is the perfect one with HTML and CSS Website tags, you can change it according to your own information. But the important part in above email syntax is the $headers variable in which we’ve defined the version and content type with character set. So now, this format will be treated as HTML email by the browser and email provider. You can change the from:<> to your own email from which you want to send an email to someone.

If you have any questions about this tutorial or any other tutorial on this website then don’t hesitate to ask your question using below commenting form, we’ll be adding more useful tutorials on web development o this blog.

About Abdul Wali

Abdul Wali is a professional blogger, marketer and web developer working online for last 5 years, he's been deeply involved in PHP, Web Development, SEO and computer video tutorials in different languages i.e English, Urdu and Pashto. You can catch him on and add him on Facebook.

Check Also

web hosting

The Best Web Hosting Providers (Tutorial)

Web hosting is one of the important aspects for establishing a business or website online. If ...

  • Latif Atif

    Hello Sir.
    Is there any project with u about online banking in PHP Plz

    • Hi, I have not created such project yet!

  • sreenath

    Hello sir,
    I want project regarding online bus travel agency in php and mysql please

    • I’ll create a project on online booking system which you can then learn, but it might take some time.

      • sreenath

        i want the website for online reservation system ? can you tell me sir please?
        finally , i want to learn php and mysql completely can u give me guidance how to learn i.e, i mean by practicing or reading ?

  • Please also tell how to get user IP and Brower detail in the email after the submission of form.

  • Eng Iroqious

    do you have any project on business directory system in php?

    • Hi,

      I don’t have at the moment, but I’ll create one very soon using PHP OOP.

      • samuel sintayehu

        do you have project online voting in php with mysql fully with admin login please contact me

  • Subhan Ch

    Abdul Wali bhai mera simple mail function bhi work ni kr rha..kya website me bhi koi configuration krni prti ha?

  • Roopavathy Baskaran

    How to send email with a file attachment using PHP.

  • samuel sintayehu

    do you have any project on online voting using php with mysql fully with admin login