Send HTML Email PHP Script – Example Code

Hello friends tired of sending normal text mail today i am going to show the script for sending HTML Mail from PHP. Sometimes we need to send some designer mails for this we will use some editor to create the mail and we will use simple mail() function for sending it. We need a good editor which is quite easy to use and integrate.  Here we will use ckeditor which is very good editor to use and easy to integrate in your application and the best part is its under Open licence so we can use it free. Lets start.

Send HTML Email PHP Script

1. Create Page

First of all we will create a page on which we will put our form with our major values. Create an .php page so that will do our php working here only.

2. Create Form

After creating the page we will create a form in it and we will describe the action as $_SERVER["PHP_SELF"]. Which means we will do our whole working in the same page and we will send our request to the same page.

3. Create Table

After creating the form we will create the table in the form and include our email main parts as textfields.

  • Receiver Email Id
  • Subject
  • Message

    We will set the from email in the code but you can do it dynamic later at your part.

4. Create form with fields

5. CkEditor working

I think you have downloaded the ckeditor so we will put our editor in it and one more thing please download the ckfinder too. So that you will be able to get the images from your pc. Now add the script part to show the editor. Your text area will become editor.

Here we put the two reference of javascript one is of jquey and another is of ckeditor js. Now your whole html code will look like this

6. PHP Script for sending mail

After getting the from we have to send our mail and this main part will be done through the PHP. So first will get the values of every fields so that we will send our mail.

Now we will check if any of the above value is null than dont send else send.

In else part we will include our mail code. First we will initialize our headers so that your mail provider treat it as HTML Format.

In header part as you can see we are putting the text/html in content-type so that it will be treated as text and html otherwise it will be treated as text only. Default is text only. Let move to design our mailer we have to write only one line code nothing else.

At last our mail sending code.

After the mail function we will check – > mail is send or not if yes than it will show mail has been sent otherwise it will show error

You can manipulate your mail according to your need but always remember about the headers. Else you will get the text format. You can copy or paste the whole code

Download from the below link

Thank You for reading the Send HTML Email PHP Script tutorial hope it will help you in your applications. If you have any comment or queries than please ask and put your valuable comments and main part dont forget to share it.

~~~~ HAPPY CODING ~~~~

1.1 KiB


  1. Jiya

    Thank you Thank You Thank You so much.

    I had been looking for this from many days. Finally got it. It is very helpful for me.

    Thanks Again

  2. Andela sivaiah

    Thank you very much this is very helpful for me
    it is working fine

    but it is going to spam in gmail?

  3. malik amjad

    outing work … very helping


Leave a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">