PHP Contact Form Send Email File Attachment Example

Today, We want to share with you PHP Contact Form Send Email File Attachment Example.In this post we will show you PHP Based Email Form With File Attachment, hear for Send Email with Attachment on Form Submission using PHP we will give you demo and example for implement.In this post, we will learn about How to create PHP based email form with file attachment with an example.

PHP Contact Form Send Email File Attachment Example

There are the Following The simple About PHP Contact Form Send Email File Attachment Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Send Email with Attachment on Form Submission using PHP, so the some major files and Directory structures for this example is following below.

  • index.php
  • do_submit.php

PHP Based Email Form With File Attachment

index.php

This is where I will make a simple HTML form and PHP server side source code for our web application. To make the forms simply all souce code copy and write it into your any text editor Like Notepad++, then save file it as index.php for Web Form HTML with File Upload Field.



    

Send Email with Attachment on Form Submission using PHP

PHP Send Email Comment with attachment files on Form Submission

Contact Request Submitted
                    

Name: '.$name.'

Email: '.$email.'

EmailSubject: '.$mailSub.'

Comment:
'.$comment.'

'; // PHP send Email Header for sender info $headers = "From: $fromName"." <".$from.">"; if(!empty($liveMainFlImg) && file_exists($liveMainFlImg)){ // PHP send Email Boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // PHP send Email Headers for file_attach $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // PHP send Email Multipart boundary $comment = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n"; // PPHP send Email reparing file_attach if(is_file($liveMainFlImg)){ $comment .= "--{$mime_boundary}\n"; $fp = @fopen($liveMainFlImg,"rb"); $data = @fread($fp,filesize($liveMainFlImg)); @fclose($fp); $data = chunk_split(base64_encode($data)); $comment .= "Content-Type: application/octet-stream; name=\"".basename($liveMainFlImg)."\"\n" . "Content-Description: ".basename($liveMainFlImg)."\n" . "Content-Disposition: attachment;\n" . " filename=\"".basename($liveMainFlImg)."\"; size=".filesize($liveMainFlImg).";\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; } $comment .= "--{$mime_boundary}--"; $backURL = "-f" . $email; // Send email $mail = mail($tosendEmail, $sendMailSub, $comment, $headers, $backURL); @unlink($liveMainFlImg); }else{ // Config or Set here content-type header for sending HTML email $headers .= "\r\n". "MIME-Version: 1.0"; $headers .= "\r\n". "Content-type:text/html;charset=UTF-8"; // Send email $mail = mail($tosendEmail, $sendMailSub, $htmlContent, $headers); } // If mail sent if($mail){ $commentStatus = 'Your contact request has been submitted successfully !'; $sendMsgCls = 'divofsuccess'; $allDataPost = ''; }else{ $commentStatus = 'Your Main contact request as well as submission failed, please try again.'; } } } }else{ $commentStatus = 'Please Full fill all the fields.'; } } ?>
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 PHP Contact Form Send Email File Attachment Example.
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.

Leave a Comment