php – SMTP Send mail using PHPMailer PHP Contact Form

Mysql Mysqli php Programming

php – SMTP Send mail using PHPMailer PHP Contact Form

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php – SMTP Send mail using PHPMailer PHP Contact Form

In this post we will show you Best way to implement How to Create Contact Form with PHPMailer to send mails, hear for How to Email Form – Simple Form to Email PHP Contact Form with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

HTML Form

<?php 
if(isset($_GET['respnose']) && $_GET['respnose'] == 'success') {
      echo '<div class="response_success"> Thank we for contacting us. We will get back to we soon. </div> ';
} ?>

     .response_success {
          background-color: #fed;
          color: green;
          border: 1px solid green; 
     }

<form name="pakainfo-contact-form" method="post" action="pakainfo-contact-process.php">
<table width="450px">
</tr>
<tr>
<td align="center">
<label for="client_name">client_name *</label>
</td>
<td align="center">

</td>
</tr>

<tr>
<td>
<label for="client_last_name">client_last_name *</label>
</td>
<td align="center">

</td>
</tr>
<tr>
<td align="center">
<label for="email">Email Address *</label>
</td>
<td align="center">

</td>

</tr>
<tr>
<td align="center">
<label for="conatct">conatct Number</label>
</td>
<td align="center">

</td>
</tr>
<tr>
<td align="center">
<label for="email_subject">email_subject</label>
</td>
<td align="center">

</td>
</tr>
<tr>
<td align="center">
<label for="message_data">message_data *</label>
</td>
<td align="center">
<textarea name="message_data" cols="25" rows="6"></textarea>
</td>

</tr>
<tr>
<td colspan="2" style="text-align:center">
 ( <a href="client_last_name">Get Help from pakainfo tut.</a> )
</td>
</tr>
</table>
</form>

PHP

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

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

   $email_to = "[email protected]";

   function simple_deid($error) {// wer error code can go here
        echo "We're sorry, but there's errors found with the form we submitted.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
   }
   if(!isset($_POST['client_name']) ||!isset($_POST['client_last_name']) ||!isset($_POST['email']) ||!isset($_POST['conatct']) ||!isset($_POST['email_subject']) || !isset($_POST['message_data'])) {
       simple_deid('We are sorry, simple but there appears new to be a problem get data with the form we submitted.'); 
   }

   $client_name = $_POST['client_name']; // data required
   $client_last_name = $_POST['client_last_name']; // data required
   $simple_email_form = $_POST['email']; // data required
   $conatct = $_POST['conatct']; // not data required
   $email_subject = $_POST['email_subject']; // data required
   $message_data = $_POST['message_data']; // data required

   $error_message = "";
   $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
   if(!preg_match($email_exp,$simple_email_form)) {
       $error_message .= 'The Email Address we just enter data does not appear to be check valid.<br />';
   }
   $exp_string = "/^[A-Za-z .'-]+$/";
   if(!preg_match($exp_string,$client_name)) {
      $error_message .= 'The client_name Name we just enter data does not appear to be check valid.<br />';
   }
   if(!preg_match($exp_string,$client_last_name)) {
       $error_message .= 'The client_last_name Name we just enter data does not appear to be check valid.<br />';
   }
   if(!preg_match($exp_string,$email_subject)) {
      $error_message .= 'The email_subject we just enter data does not appear to be check valid.<br />';
   }
   if(strlen($message_data) < 2) {
       $error_message .= 'The message_data we just enter data do not appear to be check valid.<br />';
   }
   if(strlen($error_message) > 0) {
       simple_deid($error_message);
   }
   $email_message = "\n\n";

   $email_message .= "client_name: ".clean_string($client_name)."\n";
   $email_message .= "client_last_name: ".clean_string($client_last_name)."\n";
   $email_message .= "simple_email_form: ".clean_string($simple_email_form)."\n";
   $email_message .= "conatct: ".clean_string($conatct)."\n";
   $email_message .= "email_subject: ".clean_string($email_subject)."\n";
   $email_message .= "message_data: ".clean_string($message_data)."\n";

   $mail = new PHPMailer();
   $mail->isSendmail();
   $mail->setFrom($simple_email_form, $client_name.$client_last_name);
   $mail->addAddress($email_to, 'pakainfo Varadha);
   $mail->Subject = $email_subject;
   $mail->msgHTML(file_get_contents('path/to/file/attachment-file.extension'), dirname(__FILE__));

   if (!$mail->send()) { 
      echo "Mailer Error: " . simple_deid($error);
   } else {
       header('Location: contact.php?respnose=success'); 
   }
?>


Example

I hope you have Got Email Form – Simple Form to Email PHP Contact Form 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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Multidimensional Array Searching multiple values
  2.   Laravel 5.8 - Get Last Inserted ID With Example
  3.   Create Contact Form Sending Email via SMTP PHPMailer
  4.   Http Post and Get Web Api Calls using Vuejs
  5.   Laravel If Else and Switch Case
  6.   Animation (ngAnimate) using Angular Example
  7.   jQuery AJAX laravel 6 Delete Data from database
  8.   Create Contact Form And Send Email using PHP
  9.   PHP Star Triangle Program printing Source Code
  10.   Vue Tabs Components vue-nav-tabs

Leave a Reply

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