Skip to main content

How to send multiple attachment(phpmailer) with php mailer Using Ajax,jquery

How to send multiple attachment with php mailer

Hello friends today I will tell you how to create a multiple email(attachment) sender tool with php,ajax and jquery without page refresh
Just follow two steps-



Download full code-download
Step1-create a index.php file


</center>

<center>




<br>



<br><br><br><br><br>








<center>
  <center>   

</center>



<style>
body {
width: 610px;
}

#uploadForm {
border-top: #F0F0F0 2px solid;
background: #FAF8F8;
padding: 15px 30px;
}

#uploadForm div {
margin-bottom: 20px;
}

#uploadForm div label {
margin-left: 5px
}

.demoInputBox {
padding: 10px;
border: #F0F0F0 1px solid;
border-radius: 4px;
background-color: #FFF;
width: 100%;
}

.demoInputBox:focus {
    outline:none;
}
.btnSubmit {
background-color: #263327;
border: 0;
padding: 10px 40px;
color: #FFF;
border: #F0F0F0 1px solid;
border-radius: 4px;
    cursor:pointer;
}
.btnSubmit:focus {
    outline:none;
}

</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js" type="text/javascript"></script>


<script type="text/javascript">
$(document).ready(function() { 
     $('#uploadForm').submit(function(e) {  
        if($('#email').val()) {
            e.preventDefault();
            $('#loader-icon').show();
            $(this).ajaxSubmit({ 
                target:   '#targetLayer', 
                beforeSubmit: function() {
                  $("#progress-bar").width('0%');
                },
                uploadProgress: function (event, position, total, percentComplete){ 
                    $("#progress-bar").width(percentComplete + '%');
                    $("#progress-bar").html('<div id="progress-status">' + percentComplete +' %</div>')
                },
                success:function (){
                    $('#loader-icon').hide();
                },
                resetForm: true 
            }); 
            return false; 
        }
    });
}); 

</script>

<form id="uploadForm" method="post" action="mail2.php" enctype="multipart/form-data" class="attachment-form">

<div><h2> Multiple attachment Send with php</h2></div>
  <input type="email" name="email1" id="email1" class="demoInputBox" placeholder="From"/><br>

 <input type="email" name="email" id="email" class="demoInputBox" placeholder="Email"/><br>

 <input type="text" name="subject" id="subject" class="demoInputBox" placeholder="Subject"/><br>

            <textarea name="msg" placeholder="Message"   class="demoInputBox"  cols="60" rows="6"></textarea><br>
           
          <br>
              <input type="file" name="attachment[]" id="attachment[]" class="demoInputBox" multiple="multiple"><br>

<input type="submit" id="btnSubmit" value="Send" class="btnSubmit" />

<div id="targetLayer"></div>
</form>
<div id="loader-icon" style="display:none;"><img src="LoaderIcon.gif" /></div>






</center>

<center>




<br>



<br><br><br><br><br>




Step2-
Create mail2.php,
here you have only enter your gmail id and gmail password in code




<?php 
error_reporting(0);
if(isset($_POST['email'])){
$email=$_POST['email'];
$email1=$_POST['email1'];
$msg=$_POST['msg'];
$subject=$_POST['subject'];

require 'PHPMailer-master/PHPMailerAutoload.php';

$mail = new PHPMailer();
  
  //Enable SMTP debugging.
  $mail->SMTPDebug = 0;
  //Set PHPMailer to use SMTP.
  $mail->isSMTP();
  //Set SMTP host name
  $mail->Host = "smtp.gmail.com";
  $mail->SMTPOptions = array(
                    'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    )
                );
  //Set this to true if SMTP host requires authentication to send email
  $mail->SMTPAuth = TRUE;
  //Provide username and password
  $mail->Username = "ENTER YOUR GMAIL ID";
  $mail->Password = "ENTER YOUR GMAIL ID PASSWORD";
  //If SMTP requires TLS encryption then set it
  $mail->SMTPSecure = "false";
  $mail->Port = 587;
  //Set TCP port to connect to
  
  $mail->From = $email1;
  $mail->FromName = "jignesh";
  
  $mail->addAddress($email);
  
  $mail->isHTML(true);


foreach ($_FILES["attachment"]["name"] as $k => $v) {
    $mail->AddAttachment( $_FILES["attachment"]["tmp_name"][$k], $_FILES["attachment"]["name"][$k] );
}




  $mail->Subject = $subject;
  $mail->Body = $msg;
  $mail->AltBody = "This is the plain text version of the email content";
  if(!$mail->send())
  {
   echo "Mailer Error: " . $mail->ErrorInfo;
  }
  else
  {
   echo "<b>Mail Sent Successfully.</b>";
  }
}

?>


Comments

Popular posts from this blog

How to Download Vimeo Thumbnail With PHP

Vimeo Thumbnail Downloader Tool – Vimeo Video Ka Thumbnail Download Karein Aaj ke is tutorial mein hum Vimeo Thumbnail Downloader Tool ke baare mein jaanenge. Is tool ki help se hum Vimeo video URL se us video ki thumbnail image obtain kar sakte hain. Agar aap PHP, Web Development, HTML, CSS aur Online Tools banana seekh rahe hain, to ye ek useful PHP project example hai. Vimeo Thumbnail Downloader Kya Hai? Vimeo Thumbnail Downloader ek simple tool hai jisme user Vimeo video ka URL enter karta hai. Tool Vimeo video ID ko identify karta hai aur available thumbnail image ko display karta hai. Example Vimeo URL: https://vimeo.com/389063954 Is URL mein: 389063954 Vimeo video ID hai. Vimeo Thumbnail Downloader Kaise Work Karta Hai? Is PHP script mein mainly do functions use kiye gaye hain: 1. getVimeoId() Ye function Vimeo URL se video ID find karta hai. 2. getVimeoThumb() Ye function Vimeo video ID ke basis par thumbnail information retrieve karta hai aur available thumbnail...

How To Create Contact Form With Validation-Php & Html

How To Create Contact Form - Hello Friends Ajj Me Apko Btaunga   Ki Kis Prakar   Ham Apni Website Ke Liye Contact Form Bnana Sakta Hai.( By Using   Php Contact Form With Validation Script ) Contact Form Hmare Website Ke Liye Bhut He Jrruri Hota Hai.Contact Form Ke Help Se He User Apna Message Website Owner(Admin) Ko Bhej Sakte Hai. Ajj Me Apko Btane Wala Hu Ki Kis Parkar Ham Contact Form Banakar Apne Website Me Add Kar Sakte Hai Or Apni Website Ke Liye Contact Form Bana Sakte Hai Is Contact Form Me   Ham Php Mail Function() Ka Use Karege . Ab Jab Be Koi User Contact Form Me Apni Information ,Message Details Fill Karke Submit Karega To Uski Sare Information Website Admin Ke Email Id Par A Jaiyegi Jo Be Admin Dwara   Niche Diye Gye Code Me Setup Ki Hogi. Used Language- ·          HTML ·          Jquery ·          Php ...

How To Send Sms From Website Using Php-Textlocal SMS

Hello Friends Ajj Me Apko Btaunga Ki Kis Prakar Aap Apni Website Me Free Sms Send Ka Option Integrate Kar Sakte Ho. Bulk sms in India-Best company Iske Liye Apko Sabse Pehle   Https://Www.Textlocal.In/Signup Par Signup Karke Account Create Karna Hai.Ye Ek Achi bulk sms provider company hai ·          Account Create Hone Ke Bad Aap Apna Username And Password Enter Karke Apne Dashboard Me Login Ho Jaiye( textlocal login) ·          Yanha Apko Text Local Company Dwara 10 Meassge Free Testing Ke Liye Diye Jayege ·          Aap Sms Plan Buy Kar Sakte Ho Is Company Dwara Bhut He Kam Prize Me Sms Pakage,plan provide  Kiye Jate Hai Textlocal Price Plans –  index.php <?php if(isset($_POST['code']) &&  isset($_POST['mobile'])){ // Authorisation details. $username = "enter your textlocal account email id here"; $hash = "...