How To Create Contact Form With PHPMailer To Send Mails

How To Create Contact Form With PHPMailer To Send Mails

In this Post We Will Explain About is How To Create Contact Form With PHPMailer To Send Mails With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to send email from contact form using PHPExample

In this post we will show you Best way to implement Creating a Simple Contact Form with PHP, hear for Contact form with PHP Mailer – PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Introduction

Every web-application or websites have Their Simple own contact page to get feedback and messages from visitor, As well as it will need site owners to improve Their Simple web-application or websites performance And Have idea about user experience. Here I am going to develop a simple contact form using HTML and send mails to Super Admins contacts with need of PHPMailer (A PHP Class).

And Then we need to Make a simple contact form with need of HTML forms and design it with some CSS work based on wer needs.You might save this file as contact.php

Also Read :  php - SMTP Send mail using PHPMailer PHP Contact Form

HTML Form

<?php 
if(isset($_GET['response']) && $_GET['response'] == 'success') {
      echo '<div class="success_msg" > Thank we for contacting us. We will get back to we soon. </div> ';
} ?>
<style>
     .success_msg {
          background-color: #fed;
          color: green;
          border: 1px solid green; 
     }
</style>
<form name="live-contact-form" method="post" action="live-contact-process.php">
<table width="450px">
</tr>
<tr>
<td valign="center">
<label for="fname">First Name *</label>
</td>
<td valign="center">
<input type="text" name="fname" maxlength="50" size="30">
</td>
</tr>

<tr>
<td valign="center"">
<label for="lname">Last Name *</label>
</td>
<td valign="center">
<input type="text" name="lname" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="email">Email Address *</label>
</td>
<td valign="center">
<input type="text" name="email" maxlength="80" size="30">
</td>

</tr>
<tr>
<td valign="center">
<label for="mobile">Mobile Number</label>
</td>
<td valign="center">
<input type="text" name="mobile" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="subject">Subject</label>
</td>
<td valign="center">
<input type="text" name="subject" maxlength="30" size="30">
</td>
</tr>
<tr>
<td valign="center">
<label for="message">Message *</label>
</td>
<td valign="center">
<textarea name="message" maxlength="1000" cols="25" rows="6"></textarea>
</td>

</tr>
<tr>
<td colspan="2" style="text-align:center">
<!-- We are  simple grateful to we for keeping this link in place. thank we. -->
<input type="submit" value="Submit"> ( <a href="http://pakainfo.com">Get Help from live24ucodes tut.</a> )
</td>
</tr>
</table>
</form>

Than CSS style it with the need of CSS(Cascading Style Sheet).as well as When User simple click on Submit button, and then it will send the data’s to to `live-contact-process.php`.

PHP

Here we are going to simple handle the user step by step entered data’s and simple send it to Super Admin email address at the same time we send a simple acknowledge to the and smple particular user.

Also Read :  Create Contact Form Sending Email via SMTP PHPMailer

<?php
require_once("PHPMailerAutoload.php"); //here this will simple include smtp data and pop files.

if(isset($_POST['email'])) {

   $to_email = "info@live.com";

   function mydedc($error) {// wer error code can go here
        echo "We're sorry, here but there's errors data simples found with theas simple  well as form we submitted.<hr /><hr />";
        echo $error."<hr /><hr />";
        echo "here Please go back and simple fix these errors.<hr /><hr />";
        die();
   }

   //Devlopend by livu.com e validation expected data exists
   if(!isset($_POST['fname']) ||!isset($_POST['lname']) ||!isset($_POST['email']) ||!isset($_POST['mobile']) ||!isset($_POST['subject']) || !isset($_POST['message'])) {
       mydedc('We are sorry, but there simple appears to be a some problem with the form we submitted.'); 
   }

   $fname = $_POST['fname']; //Data required
   $lname = $_POST['lname']; //Data required
   $form_email = $_POST['email']; //Data required
   $mobile = $_POST['mobile']; //Data not required
   $subject = $_POST['subject']; //Data required
   $message = $_POST['message']; //Data required

   $msg_err = "";
   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
   if(!preg_match($email_exp,$form_email)) {
       $msg_err .= 'The Email Address we entered does not appear to be valid.<hr />';
   }
   $msg_string_exp = "/^[A-Za-z .'-]+$/";
   if(!preg_match($msg_string_exp,$fname)) {
      $msg_err .= 'The USER First Name we entered does not appear to be valid.<hr />';
   }
   if(!preg_match($msg_string_exp,$lname)) {
       $msg_err .= 'The USER Last Name we entered does not appear to be valid.<hr />';
   }
   if(!preg_match($msg_string_exp,$subject)) {
      $msg_err .= 'The Last Name we entered does not simple appear to be valid.<hr />';
   }
   if(strlen($message) < 2) {
       $msg_err .= 'The Live Message we entered do not simple appear to be valid.<hr />';
   }
   if(strlen($msg_err) > 0) {
       mydedc($msg_err);
   }
   $msgbody_email = "\n\n";

   $msgbody_email .= "First Name: ".clean_string($fname)."\n";
   $msgbody_email .= "Last Name: ".clean_string($lname)."\n";
   $msgbody_email .= "Email: ".clean_string($form_email)."\n";
   $msgbody_email .= "Mobile: ".clean_string($mobile)."\n";
   $msgbody_email .= "Subject: ".clean_string($subject)."\n";
   $msgbody_email .= "Message: ".clean_string($message)."\n";

   $mail = new PHPMailer();
   $mail->isSendmail();
   $mail->setFrom($form_email, $fname.$lname);
   $mail->addAddress($to_email, 'live24u Varadha);
   $mail->Subject = $subject;
   $mail->msgHTML(file_get_contents('path/to/file/attachment-file.extension'), dirname(__FILE__));

   if (!$mail->send()) { //send the message, check for errors
      echo "Mailer Error: " . mydedc($error);
   } else {
       header('Location: contact.php?response=success'); 
   }
?>

<!--Devlopend by livu.com place wer own success html simple below -->

<?php
}
die();
?>

PHPMailer Class :

It have some extended latest features, just take simple look at here to use it effective way With Like as a CC, BCC as well as Reply-To . This is simple how we can some design a contact form with using PHP phpmailer to send emails. If We have any some queries and some doubts drop wer Message here.

Also Read :  Jquery and Vuejs conflict Solution example

Example

I hope you have Got What is php – how to send on contact form using phpmailer And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Reply

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