Monday, November 17, 2014

How to Contact Users and Admin Through PHP Email Template

Here, I am going to discuss about an email template concept. In PHP, check out how to contact user and admin through Email template. Follow the given tutorial to get detail idea about it. As a PHP Programmer, It will be very helpful for design and development of coding.

Contact Users and Admin Through PHP Email Template

                          Download                                          Live Demo


INDEX.PHP

Form action in email.php file :-

<div class="container">
  <form action="email.php" method="post">
    <p>
        <input type="text" required placeholder="Enter your name" name="firstname" />
    </p>
    <p>
        <input type="email" required placeholder="Enter email" name="email" />
    </p>

    <p>
        <input type="submit" name="send" value="Submit your Request">
    </p>
  </form>
</div>

EMAIL.PHP

In this email.php file, you need to give inline css, so that will only reflect in email where you are receiving. 

<?php
if(isset($_POST['send']))
{
   extract($_POST); 
    $to="xxx@gmail.com,$email"; //change to your mail address $email is to visitor and xxx mail is for admin.
    $strSubject="2my4edge Email Template";           
    $message .= "<html>\n";
    $message .= '<body>

<table width="100%" cellspacing="0" cellpadding="0" style="max-width:600px;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6">
  <tbody>
    <tr>
      <td width="10" bgcolor="#28354d" style="width:10px;background:linear-gradient(to bottom,#28354d 0%,#28354d 89%);background-color:#28354d">&nbsp;</td>
      <td valign="middle" align="left" height="50" bgcolor="#28354d" style="background:linear-gradient(to bottom,#28354d 0%,#28354d 89%);background-color:#28354d;padding:0;margin:0"><a style="text-decoration:none;outline:none;color:#ffffff;font-size:13px" href="https://www.2my4edge.com" target="_blank">
          <img border="0" height="30" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheeAD0kt33QD3Oyf85NNUXMEnpeGP91ORsaucEU_Ohoy1bjjoviXjK-Ps89ZYunvmjlkzglI_kUbr0u5oyFPTduczjszKkfkBVuX5QSej8RWQmwpu2hAZM3l0KPrj7ehqNx3Qla0eLJIbH/s1600/new2.png" alt="2my4edge.com" style="border:none" class="CToWUd">
        </a></td>
      <td valign="middle" align="right" height="50" bgcolor="#28354d" style="background:linear-gradient(to bottom,#28354d 0%,#28354d 89%);background-color:#28354d;padding:0;margin:0"><a style="text-decoration:none;outline:none;color:#ffffff;font-size:12px" href="http://demos.2my4edge.com" target="_blank">
        </a></td>
      <td width="10" bgcolor="#28354d" style="width:10px;background:linear-gradient(to bottom,#28354d 0%,#28354d 89%);background-color:#28354d">&nbsp;</td>
    </tr>
  </tbody>
</table>
<table width="100%" cellspacing="0" cellpadding="0" style="max-width:600px;border-left:solid 1px #e6e6e6;border-right:solid 1px #e6e6e6">
  <tbody>
    <tr>
      <td align="left" valign="top" style="color:#2c2c2c;display:block;line-height:20px;font-weight:300;margin:0 auto;clear:both;border-bottom:2px dashed #ccc;background-color:#f9f9f9;padding:20px" bgcolor="#F9F9F9"><p style="padding:0;margin:0;font-size:16px;font-weight:bold;font-size:13px"> Hi '.$firstname.'
        </p>
        <br>
        <p style="padding:0;margin:0;color:#565656;line-height:22px;font-size:13px"> Thanks for visiting our site
          <a href="http://www.2my4edge.com"> www.2my4edge.com,</a>
          This is Email customised template. i hope this tutorial is really helpfula nd useful to you. </p></td>
    </tr>
  </tbody>
</table>

.................

.................

';
    $message .= "</body>\n";    
    $headers = 'MIME-Version: 1.0'."\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
    $headers .= "From: info@2my4edge.com"; 
    $mail_sent=mail($to, $strSubject, $message, $headers);  
    if($mail_sent)
        echo "<script>alert('Thank you. we will get back to you, check your spam too'); window.location='index.php';exit();</script>";
    else
        echo "<script>alert('Sorry.Request not send'); window.location='index.php';exit();</script>";
}
?>

0 comments:

Post a Comment