• Techblog369, India
  • September 29, 2022

How to create PHP QR code and Save it to Database?

Hi In this Article I am going to show how to create QR code and save it to database also fetch QR Code in a Table Create a Page addqrcode.php in …

How to Send Multiple Files Attachment Mail using Laravel

Hi in this article i am going to show how to send multiple files attachment mail in Laravel. It’s simple example of Laravel send multiple attachment in mail. I explained simply …

Hi in this article I am going to show how to implement Email SMTP using PHP Mailer.

First you have to download PHPmailer library  from github link is given below.

https://github.com/PHPMailer/PHPMailer/tree/5.2-stable

Chose stable version

Go to your public_html folder and upload the Library and extract the file.

Create a file contact.php in a root director. You can create a file name whatever you want.

contact.php

 

 

<div class=”col-md-8″>
<div class=”cp-wrapper”>
<h4>Leave A Message!</h4>
<h2 class=”mail-failed text-danger”></h2>
<h2 class=”mail-status text-success”></h2>
<form class=”cf” id=”FormC”>
<div class=”row”>
    <div class=”col-md-6″>
        <div class=”form-group”>
                <label>Your Name*</label>
                <input type=”text” id=”name” name=”name” class=”form-control” placeholder=”Your Name Here”>
        </div>
    </div>
<div class=”col-md-6″>
        <div class=”form-group”>
                <label>Email Address*</label>
                <input type=”email” id=”email” name=”email” class=”form-control” placeholder=”Email Address Here”>
        </div>
</div>
<div class=”col-md-6″>
        <div class=”form-group”>
                <label>Subject Line*</label>
                <input type=”text” class=”form-control” id=”subject” name=”subject” placeholder=”Subject Of Massage”>
        </div>
</div>
<div class=”col-md-6″>
        <div class=”form-group”>
                <label>Telephone Number*</label>
                <input type=”text” id=”phone” name=”phone” class=”form-control” placeholder=”Phone Number”>
        </div>
</div>
<div class=”col-md-12″>
        <div class=”form-group”>
            <label>Your Message*</label>
            <textarea class=”form-control” id=”body” name=”body” placeholder=”Write Your Message”></textarea>
        </div>
<button type=”button” id=”contactUS” name=”contactUS” class=”cf-btn”>Send Now</button>
<!– <div class=”cf-msg” style=”display: none;”></div> –>
</div>
</div>
</form>
</div>
</div>
we are using jQuery Ajax so your page will not be reload when submit button will press.
Create a file script.js.php and link it to your footer page like below
<?phpinclude(‘script.js.php’);?>
Now paste the below code on scipts.js.php file.
<script>
  $(document).ready(function() {
   $(‘#contactUS’).click(function(e){
    e.preventDefault();
    //  alert(“hjkhkjhkj”);
      var name =$(“#name”).val();
      var email =$(“#email”).val();
      var phone =$(“#phone”).val();
      var subject =$(“#subject”).val();
      var body =$(“#body”).val();
    //   console.log(name);
    //   console.log(email);
    //   console.log(phone);
    //   console.log(subject);
    //   console.log(body);
      if(name==null || name==””,email==null || email==””,phone==null || phone==””,subject==null || subject==””,body==null || body==””)
      {
        alert(“Please Fill All Required Field”);
        return false;
      }
      else{
        $.ajax({
          url:’/ajax/sendEmail.php’,
          method:’POST’,
          data:{
            name: name,
            email: email,
            phone: phone,
            subject: subject,
            body: body
          },
          dataType:’json’,
          success: function(result){
            if(result == 1){
                console.log(result);
                $(‘#FormC’)[0].reset();
                $(‘.mail-status’).show();
                $(‘.mail-status’).html(‘Your Message has been Sent!!’);
                $(‘.mail-status’).delay(4000).fadeOut(‘slow’);
            }else{
                $(‘.mail-failed’).show();
                $(“.mail-failed”).html(‘Something Error!! Your Message not been Sent!!’);
                $(‘.mail-failed’).delay(4000).fadeOut(‘slow’);
            }
          }
        });
      }
      });
    });
  </script>

Now Create a folder name ajax and under the ajax folder create a file

sendEmail.php  and paste the below code.
<?php
header(‘Content-Type: application/json’);
include(‘../Connection/Functions.php’);  //Database Conectivity
require “../PHPMailer/PHPMailerAutoload.php”;
// Data Come from database
    $edata = ShowEmailSetting();
    $oEmail = $edata[’emailUser’];
    $oPass = $edata[’emailPass’];
    $osmtp = $edata[‘esmtp’];
    $oPort = $edata[‘eport’];
    $oEmailEnc= $edata[’emailenc’];
    $oreply= $edata[’emsilreply’];
    function smtpmailer($to, $from, $from_name, $subject, $body)
    {
        global $oEmail,$oPass,$osmtp,$oPort,$oEmailEnc;
        $mail = new PHPMailer();
        // $mail->SMTPDebug =3;
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = $oEmailEnc;
        $mail->Host =$osmtp;
        $mail->Port = $oPort;
        $mail->Username = $oEmail;
        $mail->Password = $oPass;
        // $mail->SMTPAuth = true;
        // $mail->SMTPSecure = ‘ssl’;
        // $mail->Host =’mail.example.com’;
        // $mail->Port = 465;
        // $mail->Username = ‘contact@example.com’;
        // $mail->Password = ‘yourpass’;
        $mail->IsHTML(true);
        $mail->From=$oEmail;
        $mail->FromName=$from_name;
        $mail->Sender=$from;
        $mail->AddReplyTo($from, $from_name);
        $mail->Subject = $subject;
        $mail->Body = “<table><tr><th>Name</th><th>Email</th><th>Phone</th><th>Subject</th><th>Message</th></tr>
        <tr><td>”.$_POST[“name”].”</td><td>”.$_POST[“email”].”</td><td>”.$_POST[“phone”].”  </td><td>”.$_POST[“subject”].”</td><td>”.$_POST[“body”].”</td></tr></table>”;
        $mail->AddAddress($to);
        if(!$mail->Send())
        {
             echo ‘0’;
        }
        else
        {
            echo ‘1’;
        }
    }
    $to =$oreply;
    $from = $_POST[’email’];
    $name = $_POST[‘name’];
    $subj = $_POST[‘subject’];
    $msg = $_POST[‘body’];
    $error=smtpmailer($to,$from, $name,$subj,$msg);
?>
Thanks for reading…

Author

admin@techblog369.in

Leave a Reply

Your email address will not be published.