Today, We want to share with you PHP Contact Form Send Email Add More File Attachment.
In this post we will show you PHP Contact Form with file Multiple attachment, hear for attach two or multiple files and send mail in PHP we will give you demo and example for implement.
In this post, we will learn about PHP Contact Form with Add More File Attachment Option with an example.
PHP Contact Form Send Email Add More File Attachment
There are the Following The simple About PHP Contact Form Send Email Add More File Attachment Full Information With Example and source code.and my previous POST learn To multiple image upload in php demo
Contact Form HTML with Attachment
Contact Form HTML with multiple Add More Attachment – index.php
<!DOCTYPE html> <html> <head> <link href="yourdomainame/style.css" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> <title>PHP Send Email Dynamically Add More Multiple File Attachment</title> </head> <body> <h1>PHP Send Email Dynamically Add More Multiple File Attachment</h1> <div class="pakainfo attachment-form-container"> <form name="sendmailFrm" id="sendmailFrm" method="post" action="" enctype="multipart/form-data" onsubmit="return frmempvalidate()"> <div class="input-row"> <label style="padding-top: 20px;">Name</label> <span id="employeeName-info" class="info"></span><br /> <input type="text" class="input-field" name="employeeName" id="employeeName" /> </div> <div class="input-row"> <label>Email</label> <span id="employeeEmail-info" class="info"></span><br /> <input type="text" class="input-field" name="employeeEmail" id="employeeEmail" /> </div> <div class="input-row"> <label>Subject</label> <span id="employeeSubject-info" class="info"></span><br /> <input type="text" class="input-field" name="employeeSubject" id="employeeSubject" /> </div>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> <script type="text/javascript"> function frmempvalidate() { var frmempvalid = true; $(".info").html(""); var employeeName = document.forms["sendmailFrm"]["employeeName"].value; var employeeEmail = document.forms["sendmailFrm"]["employeeEmail"].value; var employeeSubject = document.forms["sendmailFrm"]["employeeSubject"].value; var employeeMessage = document.forms["sendmailFrm"]["employeeMessage"].value; if (employeeName == "") { $("#employeeName-info").html("(required)"); $("#employeeName").css('background-color', '#3d3d3d'); frmempvalid = false; } if (employeeEmail == "") { $("#employeeEmail-info").html("(required)"); $("#employeeEmail").css('background-color', '#3d3d3d'); frmempvalid = false; } if (!employeeEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) { $("#employeeEmail-info").html("(infrmempvalid)"); $("#employeeEmail").css('background-color', '#3d3d3d'); frmempvalid = false; } if (employeeSubject == "") { $("#employeeSubject-info").html("(required)"); $("#employeeSubject").css('background-color', '#3d3d3d'); frmempvalid = false; } if (employeeMessage == "") { $("#employeeMessage-info").html("(required)"); $("#employeeMessage").css('background-color', '#3d3d3d'); frmempvalid = false; } return frmempvalid; } function multipleaddAttachment() { $(".attachment-row:last").clone().insertAfter(".attachment-row:last"); $(".attachment-row:last").find("input").val(""); } </script>
PHP Mail Send with Multiple Attachments
PHP Mail Sending Script with Multiple Attachments
We used simple PHPMailer SMTP to multiple Files or images(Attachments) send the each employeeEmail contact form email by using pure goole product Gmail SMTP
<?php if(!empty($_POST["send"])) { require_once ('phpmailer/class.phpmailer.php'); //setting some smtp Mail $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 0; $mail->SMTPAuth = TRUE; $mail->Port = 587; // port set $mail->Username = "Set SMTP USERNAME([email protected])"; $mail->Password = "Set SMTP PASSWORD(98982256245)"; $mail->Mailer = "smtp"; if (isset($_POST["employeeEmail"])) { $employeeEmail = $_POST["employeeEmail"]; } if (isset($_POST["employeeName"])) { $employeeName = $_POST["employeeName"]; } if (isset($_POST["employeeSubject"])) { $employeeSubject = $_POST["employeeSubject"]; } if (isset($_POST["employeeMessage"])) { $comments = $_POST["employeeMessage"]; } $mail->SetFrom($employeeEmail, $employeeName); $mail->AddReplyTo($employeeEmail, $employeeName); $mail->AddAddress("YOUR Google or any other RECIPIENT address of Email"); // set recipient email address $mail->Subject = $employeeSubject; $mail->WordWrap = 80; $mail->MsgHTML($comments); $mail->IsHTML(true); $mail->SMTPSecure = 'tls'; $mail->Host = 'smtp.gmail.com'; if (! empty($_FILES['attachment'])) { $total = count($_FILES['attachment']['name']); if ($total > 0) { // here Attaching two or more multiple images or files with the send email for ($attach = 0; $attach < $total; $attach ++) { if (! empty($_FILES["attachment"]["name"])) { $tmpfl = $_FILES["attachment"]["tmp_name"][$attach]; $employeeFlname = $_FILES["attachment"]["name"][$attach]; $mail->AddAttachment($tmpfl, $employeeFlname); } } } } if (! $mail->Send()) { $message = "Problem in sending email"; $type = "error"; } else { $message = "Your Mail sent successfully, Good Luck"; $type = "success"; } }
Angular 6 CRUD Operations Application Tutorials
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about Send Multiple Attachment In Email Using PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.