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>";
}
}
?>
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>";
}
}
?>
ConversionConversion EmoticonEmoticon