PHP Mail Attachment – Php Send Email File-Images Attachments

PHP Mail Attachment – Php Send Email File-Images Attachments

In this Post We Will Explain About is PHP Mail Attachment – Php Send Email File-Images Attachments 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 How to Send Email with Attachment in PHPExample

In this post we will show you Best way to implement php send email with attachment example, hear for how to create php based email form with file attachmentwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

PHP mail attachment : structure

index.php
do_email_submit.php
contact_validation.js

Phase 1 : Create Email Form HTML index.php

	
<div class="container">
<h1>Example: simple Send Email template with Attachment in PHP</h1>
<div id='success_message' class='hidden'>
<h2>Your Email or Mail Sent Successfully done!</h2>
<p><strong>You will be in Good Luck touch soon.</strong></p>
</div>
	<form action='do_email_submit.php' class="form-email" method="post" id="submit_email_form" enctype='multipart/form-data'>
		<div id="error">
		</div>
			<div class="form-group">
			<input type="input" class="form-control" placeholder="client_name" name="client_name" id="client_name" />
			<span id="check-e"></span>
			</div>
			<div class="form-group">
			<input type="email" class="form-control" placeholder="client_email address" name="client_email" id="client_email" />
			<span id="check-e"></span>
			</div>
			<div class="form-group">
			<input type="file" class="form-control" placeholder="File" name="data_attach" id="data_attach" />
			</div>
			<div class="form-group">
			<textarea cols="50" rows="5" id="comments" name="comments" placeholder='comments'></textarea>
			</div>
			<hr />
			<div class="form-group">
			<button type="submit" class="btn btn-default" name="do_email_submit" id="do_email_submit">
			Send Email
			</button>
			</div>
	</form>
</div>

Phase 2: Validate Email Form contact_validation.js

$('document').ready(function() {
(function() {
	$('form').ajaxForm({
		beforeSubmit: function() {
		$("#submit_email_form").validate({
			rules: {
				client_name: {
				required: true,
				minlength : 3
				},
				client_email: {
				required: true,
				email: true
				},
				data_attach: {
				required: true
				},
				comments: {
				required: true
				}
			},
			messages: {
			client_name: {
			required:"Please enter client_name",
			minlength: "Please enter a valid client_name"
			},
			client_email:{
			required: "Please enter your client_email",
			minlength: "Please enter a valid client_email address",
			},
			data_attach: "Please Choose data_attach Images / files",
			comments: "Please enter comments"
			},
		});
		var flag= $('#submit_email_form').valid();
		if(!flag){
		return false;
		}
	},
	complete: function(xhr) {
	$("#submit_email_form").addClass("hidden");
	$("#success_message").removeClass("hidden");
	}
	});
})();
});

Phase 3: Implement simple Email Send Logic with Attachment some File or Images using PHPMailer(do_email_submit.php)

<?php
require 'PHPMailer/PHPMailerAutoload.php';
try {
	if(isset($_POST['do_email_submit'])) {
		$mail = new PHPMailer;
		$mail->FromName = $_POST['client_name'];
		$to_email = $_POST['client_email'];
		$mail->AddAddress($to_email);
		$mail->From = "[email protected]";
		$mail->Subject = "Test Client-Email Send using PHP and jquery ajax";
		$contentbody = "<table>
		<tr>
		<th colspan='2'>This is a first test email</th>
		</tr>
		<tr>
		<td>client_name :</td>
		<td>".$_POST['client_name']."</td>
		</tr>
		<tr>
		<td>client_email : </td>
		<td>".$_POST['client_email']."</td>
		</tr>
		<tr>
		<td>comments : </td>
		<td>".$_POST['comments']."</td>
		</tr>
		<table>";
		$contentbody = preg_replace('/\\/','', $contentbody);
		$mail->MsgHTML($contentbody);
		$mail->IsSendmail();
		$mail->AddReplyTo("[email protected]");
		$mail->AltBody = "To view the all comments, please simple use an HTML all elements compatible email simple viewer!";
		$mail->WordWrap = 90;
		$mail->AddAttachment($_FILES['data_attach']['tmp_name'], $_FILES['data_attach']['name']);
		$mail->IsHTML(true);
		$mail->Send();
		echo 'The comments has been sent.';
	}
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>

Example

I hope you have Got What is send email with attachment in php using phpmailer 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.   PHP Multiple Email Attachments with Sending Email AJAX Multiple File upload
  2.   php send mail attachment with Pear Mail
  3.   How to Get the Current URL with VueJS?
  4.   Laravel 7/6 Pluck Example | How to use pluck() in Laravel 6
  5.   Difference between break and continue
  6.   Time Ago Function Helper Class in PHP
  7.   PHP Contact Form Send Email Add More File Attachment
  8.   Laravel 5.8 Global Blade view variable
  9.   PHP Contact Form Send Email File Attachment Example
  10.   Laravel 6 Pagination Link Customizations Example