Newer
Older
EmailSender / submit.php
0xRoM on 8 Sep 2023 3 KB first commit
  1. <?php
  2. include_once('mail.php');
  3.  
  4. // Define the known MD5 hash for the password
  5. $knownPasswordHash = '098f6bcd4621d373cade4e832627b4f6'; // test == 098f6bcd4621d373cade4e832627b4f6
  6. $uploadDirectory = 'uploads/'; // Replace with your desired upload directory
  7.  
  8. // Check if the request is a POST request and the password is provided
  9. if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['pass'])) {
  10. // Get the password from the form data
  11. $password = $_POST['pass'];
  12.  
  13. // Verify the password against the known MD5 hash
  14. if (md5($password) === $knownPasswordHash) {
  15. // Check if the required fields are set
  16. $requiredFields = ['from_email', 'to_email', 'subject', 'plaintext_content'];
  17. $missingFields = [];
  18.  
  19. foreach ($requiredFields as $field) {
  20. if (!isset($_POST[$field]) || empty($_POST[$field])) {
  21. $missingFields[] = $field;
  22. }
  23. }
  24.  
  25. // If there are missing required fields, return an error message
  26. if (!empty($missingFields)) {
  27. echo "Mising required data (from email, to email, subject and plaintext content) ";
  28. } else {
  29. // All checks passed, proceed to send the email
  30. $fromEmail = $_POST['from_email'];
  31. $toEmail = $_POST['to_email'];
  32. $message = $_POST['plaintext_content'];
  33. $subject = $_POST['subject'];
  34.  
  35. if (isset($_POST['html_content'])) {
  36. $htmlContent = $_POST['html_content'];
  37. $mail = new Mail($toEmail, $fromEmail, $subject, $message, $htmlContent);
  38. }else{
  39. $mail = new Mail($toEmail, $fromEmail, $subject, $message, $htmlContent);
  40. }
  41.  
  42. // Additional processing for dynamic headers (if present)
  43. foreach ($_POST as $key => $value) {
  44. if (strpos($key, 'header_name_') === 0) {
  45. $id = substr($key, strlen('header_name_'));
  46. $headerName = $value;
  47. $headerValueKey = 'header_value_' . $id;
  48. if (isset($_POST[$headerValueKey])) {
  49. $headerValue = $_POST[$headerValueKey];
  50. $mail->add_header($headerName.": ".$headerValue);
  51. }
  52. }
  53. }
  54.  
  55. // Check if an attachment is provided
  56. if (isset($_FILES['attachment']) && $_FILES['attachment']['error'] === 0) {
  57. // Handle the uploaded file
  58. $uploadedFile = $_FILES['attachment'];
  59. $uploadedFilePath = $uploadDirectory . $uploadedFile['name'];
  60.  
  61. // Move the uploaded file to the desired directory
  62. if (move_uploaded_file($uploadedFile['tmp_name'], $uploadedFilePath)) {
  63. // Add the attachment to the email
  64. $mail->add_attachment($uploadedFilePath);
  65. } else {
  66. echo "Failed to upload the attachment.";
  67. }
  68. }
  69.  
  70.  
  71. // Send the email
  72. if ($mail->send()) {
  73. echo "Success";
  74. } else {
  75. echo "Failed to send the email.";
  76. }
  77. }
  78. } else {
  79. echo "Invalid password.";
  80. }
  81. } else {
  82. echo "Invalid request.";
  83. }
  84. ?>
Buy Me A Coffee