Send email with html template using php - Mostlikers

16 February, 2015

Send email with html template using php

Today i want to explain about how to send email with html template using php. Normally we use php mailer function for sending email with some text also. But here i have design one html template along to send with mail script. Follow below code and have look at live demo.

Email template in php


Live demo            Download

Html

<form action="email.php" method="post">
    <p>
      <input type="text" required name="firstname" />
    </p>
    <p>
      <input type="email" required name="email" />
    </p>s    
    <p>
      <input type="submit" name="send" value="Submit your Request">
    </p>
  </form>

Email.php

Extract($_POST) - Extracting Post Variables From.
file_get_contents - Html design form to get the function.
$mail - PHP mailer value along email template.
<?php
if(isset($_POST['send']))
{
   extract($_POST); 
    $to="$email"; //change to ur mail address
    $strSubject="Mostlikers | Email template | $firstname";
    $message =  file_get_contents('template.php');              
    $headers = 'MIME-Version: 1.0'."\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
    $headers .= "From: info@mostlikers.com"; 
    
    $mail_sent=mail($to, $strSubject, $message, $headers);  
    if($mail_sent)
        echo "<script>alert('Thank you. we will get back to you');
               window.location='index.php';exit();</script>";
    else
        echo "<script>alert('Sorry.Request not send');
             window.location='index.php';exit();</script>";
}
?>

HTML Email Template (template.php)

This one sample html design. you can create own html code design code. We have all ready design good design please download and use that template.
<html>
<body>
<table width="100%" cellspacing="0" cellpadding="0">
    <tr><td bgcolor="#005387"> Name : Your name </td></tr>
    <tr><td bgcolor="#005387"> Email : xas@ymail.co </td></tr>
</table>
</body>
</html>
<html>
Try it your self







2 comments: