Want to Learn Digital Marketing tips, trends, and strategy Follow Our Blog and Youtube Channel

How to Send HTML Form to Email with Attachment using PHP

Hello Friends once again welcome to digital magnate blog. in this Blog we learn How To Send HTML Form to Email with Attachment using PHP. Thanks for Big Support of all of you To My Previous Blog About How To send HTML Form Data to Email using PHP. So made a new tutorial for How to Send HTML Form to Email with Attachment using PHP function.



kš—¶š—»š—±š—¹š˜† š˜€š˜‚š—Æš˜€š—°š—暝—¶š—Æš—² š˜š—¼ š—¼š˜‚š—æ š—°š—µš—®š—»š—»š—²š—¹ š—³š—¼š—æ š—ŗš—¼š—暝—² š˜ƒš—¶š—±š—²š—¼š˜€ Click here ➜ https://www.youtube.com/c/Digitalmagnate

so lets started..

 

The HTML form

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Digital Magnate-Contact Form</title> </head> <body> <form action="mail.php" method="post" enctype="multipart/form-data"> <input type="text" name="name" placeholder="Name"> <br> <input type="text" name="email" placeholder="email"> <br> <input type="text" name="message" placeholder="Message"> <br> <input type="file" name="file"> <br> <input type="submit" value="Submit"> </form> </body> </html>


mail.php

<?php $filenameee = $_FILES['file']['name']; $fileName = $_FILES['file']['tmp_name']; $name = $_POST['name']; $email = $_POST['email']; $usermessage = $_POST['message']; $message ="Name = ". $name . "\r\n Email = " . $email . "\r\n Message =" . $usermessage; $subject ="Digital Magnate-Contact from"; $fromname ="Digital Magnate"; $fromemail = 'noreply@digitalmagnate.blogpost.com'; $mailto = 'ramanrana56@gmail.com'; //the email ID where u want to get this email $content = file_get_contents($fileName); $content = chunk_split(base64_encode($content)); // a random hash will be necessary to send mixed content $separator = md5(time()); // carriage return type (RFC) $eol = "\r\n"; // main header (multipart mandatory) $headers = "From: ".$fromname." <".$fromemail.">" . $eol; $headers .= "MIME-Version: 1.0" . $eol; $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol; $headers .= "Content-Transfer-Encoding: 7bit" . $eol; $headers .= "This is a MIME encoded message." . $eol; // message $body = "--" . $separator . $eol; $body .= "Content-Type: text/plain; charset=\"iso-8859-1\"" . $eol; $body .= "Content-Transfer-Encoding: 8bit" . $eol; $body .= $message . $eol; // attachment $body .= "--" . $separator . $eol; $body .= "Content-Type: application/octet-stream; name=\"" . $filenameee . "\"" . $eol; $body .= "Content-Transfer-Encoding: base64" . $eol; $body .= "Content-Disposition: attachment" . $eol; $body .= $content . $eol; $body .= "--" . $separator . "--"; //SEND Mail if (mail($mailto, $subject, $body, $headers)) { echo "Email Sent...."; // Your Massage after Email Sent } else { echo "mail send ... ERROR!"; print_r( error_get_last() ); }



For more details and to know how to implement this Check out our Code.

Download Source Code : 

                                    

0 Comments