Create Contact Form Sending Email via SMTP PHPMailer

Create Contact Form Sending Email via SMTP PHPMailer

In this Post We Will Explain About is Create Contact Form Sending Email via SMTP PHPMailer 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 Sending mail using SMTP from localhost using PHPMailerExample

In this post we will show you Best way to implement Sending Email With PHPMailer and SMTP, hear for Sending e-mails via SMTP with PHPMailer and GMailwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

send_contact_mail.php

<?php 
if(isset($_GET['result']) && $_GET['result'] == 'success') {
      echo '<div class="contact_success_message" > Thanks a lot for contacting us. and then We will get call or  back to you soon asap. </div> ';
} ?>
<style>
     .contact_success_message {
          background-color: #3D3D3D;
          color: yellow;
          border: 2px solid yellow; 
     }
</style>
<form name="live-contact-form" method="post" action="live-contact-process.php">
<table width="480px">
</tr>
<tr>
<td align="center">
<label for="usre_first_nm">Your USER First Name *</label>
</td>
<td align="center">
<input type="text" name="usre_first_nm" maxlength="48" size="28">
</td>
</tr>

<tr>
<td align="center"">
<label for="usre_last_nm">Your USER Last Name *</label>
</td>
<td align="center">
<input type="text" name="usre_last_nm" maxlength="48" size="28">
</td>
</tr>
<tr>
<td align="center">
<label for="email_address">Your Email Address *</label>
</td>
<td align="center">
<input type="text" name="email_address" maxlength="80" size="28">
</td>

</tr>
<tr>
<td align="center">
<label for="mail_cellphone">Your cellphone Number</label>
</td>
<td align="center">
<input type="text" name="mail_cellphone" maxlength="28" size="28">
</td>
</tr>
<tr>
<td align="center">
<label for="mail_subject">Your subject</label>
</td>
<td align="center">
<input type="text" name="mail_subject" maxlength="28" size="28">
</td>
</tr>
<tr>
<td align="center">
<label for="messages">Messages *</label>
</td>
<td align="center">
<textarea name="messages" maxlength="800" cols="24" rows="6"></textarea>
</td>

</tr>
<tr>
<td colspan="2" style="text-align:center">
<!-- We are happy and grateful to you for always keeping this useful link in place. thanks a lot. -->
<input type="submit" value="Submit"> ( <a href="https://www.pakainfo.com/send-mail-using-smtp-php-script/">Get Help from live24u tut.</a> )
</td>
</tr>
</table>
</form>

live-contact-process.php

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.


Download Project Scripts

<?php
require_once("PHPMailerAutoload.php"); 

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

   $email_to = "[email protected]";

   function died($error) {
        echo "We're very hartly sorry, but there are some errors found with the conatct form you submitted.<hr /><br />";
        echo $error."<br /><hr />";
        echo "Please go First step and fix uour errors.<hr /><br />";
        die();
   }

   if(!isset($_POST['usre_first_nm']) ||!isset($_POST['usre_last_nm']) ||!isset($_POST['email_address']) ||!isset($_POST['mail_cellphone']) ||!isset($_POST['mail_subject']) || !isset($_POST['messages'])) {
       died('We're very hartly sorry, but there are some errors found with the conatct form you submitted.'); 
   }

   $usre_first_nm = $_POST['usre_first_nm']; 
   $usre_last_nm = $_POST['usre_last_nm'];
   $email_address_form = $_POST['email_address']; 
   $mail_cellphone = $_POST['mail_cellphone']; 
   $mail_subject = $_POST['mail_subject']; 
   $messages = $_POST['messages'];

   $user_error_msg = "";
   $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
   if(!preg_match($email_exp,$email_address_form)) {
       $user_error_msg .= 'The USER Email Address Its entered does not show to be success!.<br />';
   }
   $livestr_exp = "/^[A-Za-z .'-]+$/";
   if(!preg_match($livestr_exp,$usre_first_nm)) {
      $user_error_msg .= 'The USER First Name Its entered does not show to be success!.<br />';
   }
   if(!preg_match($livestr_exp,$usre_last_nm)) {
       $user_error_msg .= 'The USER Last Name Its entered does not show to be success!.<br />';
   }
   if(!preg_match($livestr_exp,$mail_subject)) {
      $user_error_msg .= 'The USER Last Name Its entered does not show to be success!.<br />';
   }
   if(strlen($messages) < 2) {
       $user_error_msg .= 'The USER Messages Its entered do not show to be success!.<br />';
   }
   if(strlen($user_error_msg) > 0) {
       died($user_error_msg);
   }
   $body_msg = "\n\n";

   $body_msg .= "USER First Name: ".clean_string($usre_first_nm)."\n";
   $body_msg .= "USER Last Name: ".clean_string($usre_last_nm)."\n";
   $body_msg .= "USER Email: ".clean_string($email_address_form)."\n";
   $body_msg .= "USER mail_cellphone: ".clean_string($mail_cellphone)."\n";
   $body_msg .= "USER mail_subject: ".clean_string($mail_subject)."\n";
   $body_msg .= "USER Messages: ".clean_string($messages)."\n";

   //create a simple PHP object
   $mail = new PHPMailer();
   
   //check send mail
   $mail->isSendmail();
   
   //all set form data for users
   $mail->setFrom($email_address_form, $usre_first_nm.$usre_last_nm);
   $mail->addAddress($email_to, 'live24u Dsp Patel);
   $mail->mail_subject = $mail_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: " . died($error);
   } else {
       header('Location: send_contact_mail.php?result=success'); 
   }
?>

<?php
}
die();
?>

Example

  PHP Laravel Get Environment Variables Example Tutorial

I hope you have Got What is How to Create Contact Form with PHPMailer to send mails 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.   ng-init Multiple Values using Angular Example
  2.   Create Contact Form And Send Email using PHP
  3.   PHPMailer Sending Emails using PHP Code
  4.   Send Simple Mail Function using PHP
  5.   php - SMTP Send mail using PHPMailer PHP Contact Form
  6.   Laravel 5.7 Image File Validator Validation
  7.   How to Check If Array is Empty in Laravel Blade?
  8.   Laravel Drop hascolumn if exists in Migration
  9.   delete Query In Codeigniter Example Tutorial
  10.   PHP Send Email using SMTP Authentication

Leave a Reply

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