Send Beautiful HTML Email using PHP

Using PHP mail() function we can easily send the text email. But most of the cases we need to send nice HTML email to the users. Like registration welcome email, contact request submission email, invoice email etc. You can easily send the HTML email using PHP mail() function with our PHP HTML email script.

We have created a welcome email HTML template and sent to the email. From the Demo link you can receive the HTML email template into inbox. Download full source code and HTML email template from the Download link.


PHP Code:

Content-type header is mandatory for sending HTMl email. The additional headers are used for adding From, Cc, Bcc etc. $htmlContent variable hold the HTML contents of the email.

$subject "Beautiful HTML Email using PHP by CodexWorld";

$htmlContent '
        <title>Welcome to CodexWorld</title>
        <h1>Thanks you for joining with us!</h1>
        <table cellspacing="0" style="border: 2px dashed #FB4314; width: 300px; height: 200px;">
            <tr style="background-color: #e0e0e0;">
                <th>Website:</th><td><a href=""></a></td>

// Set content-type header for sending HTML email
$headers "MIME-Version: 1.0" "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" "\r\n";

// Additional headers
$headers .= 'From: CodexWorld<>' "\r\n";
$headers .= 'Cc:' "\r\n";
$headers .= 'Bcc:' "\r\n";

// Send email
$successMsg 'Email has sent successfully.';
$errorMsg 'Email sending fail.';

If you want to add huge HTML contents you can put the HTML contents into a file (email_template.html) and get the file contents using file_get_contents() function.

$htmlContent file_get_contents("email_template.html");

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request

Recommended Tutorials For You


  1. Andreas Said...
    • CodexWorld Said...
  2. Chris Said...
  3. WebPhenom Said...
  4. Liza Said...
  5. Nida Akram Said...
  6. Amit Kumar Mishra Said...
  7. Muzammil Said...
  8. Jeff Said...
  9. Anas Said...
    • CodexWorld Said...
  10. Gautam Nagraj Said...
  11. Ankit Yaduwanshi Said...
  12. Kevin Said...
  13. Hiepnh Said...
  14. Lutfu Can Said...
  15. Kamlesh Said...
  16. Amit Tiwari Said...
  17. Cp Said...
  18. Carl Said...

Leave a reply