[
  {
    "path": ".gitignore",
    "content": "/**/node_modules/\n/dist/\n/.git/\n/app/css/\n/**/_backstage\n/**/package-lock.json\n/**/Thumbs.db\n/**/*.DS_Store\n"
  },
  {
    "path": "readme.md",
    "content": "<h2>Universal PHP Mail Feedback Script</h2>\n\n<h3>How to use uniMail</h3>\n\n<ol>\n  <li>Connect <code>script.js</code> file to your project and Specify location <code>mailPath</code> in this file</li>\n  <li>Add <code>uniForm</code> class to the desired <code>&lt;form&gt;</code> tags in HTML (like index.html example)</li>\n  <li>Add <strong>Hidden Required Fields</strong> to your forms in HTML (like index.html example)</li>\n  <li>Add any set of fields to your forms in HTML (like index.html example)</li>\n  <li>Done!</li>\n</ol>\n"
  },
  {
    "path": "script/index.html",
    "content": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <title>uniMail</title>\n  <script src=\"script.js\" defer></script>\n</head>\n<body>\n\n  <form class=\"uniForm\">\n\n    <h3>Form 1</h3>\n\n    <!-- Hidden Required Fields -->\n    <input type=\"hidden\" name=\"project_name\" value=\"Site Name\">\n    <input type=\"hidden\" name=\"admin_email\" value=\"admin@gmail.com\">\n    <input type=\"hidden\" name=\"form_subject\" value=\"Form Subject 1\">\n    <!-- END Hidden Required Fields -->\n\n    <input type=\"text\" name=\"Name\" placeholder=\"You name...\" required><br>\n    <input type=\"text\" name=\"E-mail\" placeholder=\"You E-mail...\" required><br>\n    <input type=\"text\" name=\"Phone\" placeholder=\"You phone...\"><br>\n\n    <button>Send</button>\n\n  </form>\n\n  <form class=\"uniForm\">\n\n    <h3>Form 2</h3>\n\n    <!-- Hidden Required Fields -->\n    <input type=\"hidden\" name=\"project_name\" value=\"Site Name\">\n    <input type=\"hidden\" name=\"admin_email\" value=\"admin@gmail.com\">\n    <input type=\"hidden\" name=\"form_subject\" value=\"Form Subject 2\">\n    <!-- END Hidden Required Fields -->\n\n    <input type=\"text\" name=\"Name\" placeholder=\"You name...\" required><br>\n    <input type=\"text\" name=\"E-mail\" placeholder=\"You E-mail...\" required><br>\n    <input type=\"text\" name=\"Phone\" placeholder=\"You phone...\"><br>\n\n    <button>Send</button>\n\n  </form>\n\n</body>\n</html>"
  },
  {
    "path": "script/mail.php",
    "content": "<?php\n\n$method = $_SERVER['REQUEST_METHOD'];\n$c = true;\n\nif ( $method === 'POST' ) {\n\n  $project_name = trim($_POST[\"project_name\"]);\n  $admin_email  = trim($_POST[\"admin_email\"]);\n  $form_subject = trim($_POST[\"form_subject\"]);\n\n  foreach ( $_POST as $key => $value ) {\n    if ( $value != \"\" && $key != \"project_name\" && $key != \"admin_email\" && $key != \"form_subject\" ) {\n      $message .= \"\n      \" . ( ($c = !$c) ? '<tr>':'<tr style=\"background-color: #f8f8f8;\">' ) . \"\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>\n      </tr>\n      \";\n    }\n  }\n} else if ( $method === 'GET' ) {\n\n  $project_name = trim($_GET[\"project_name\"]);\n  $admin_email  = trim($_GET[\"admin_email\"]);\n  $form_subject = trim($_GET[\"form_subject\"]);\n\n  foreach ( $_GET as $key => $value ) {\n    if ( $value != \"\" && $key != \"project_name\" && $key != \"admin_email\" && $key != \"form_subject\" ) {\n      $message .= \"\n      \" . ( ($c = !$c) ? '<tr>':'<tr style=\"background-color: #f8f8f8;\">' ) . \"\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>\n      </tr>\n      \";\n    }\n  }\n};\n\n$message = \"<table style='width: 100%;'>$message</table>\";\n\nfunction adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };\n\n$headers = \"MIME-Version: 1.0\" . \"\\r\\n\" .\n\"Content-Type: text/html; charset=utf-8\" . \"\\r\\n\" .\n\"From: \" . adopt($project_name) . \" <\" . $admin_email . \">\" . \"\\r\\n\" .\n\"Reply-To: \" . $admin_email . \"\" . \"\\r\\n\";\n\nmail($admin_email, adopt($form_subject), $message, $headers );\n"
  },
  {
    "path": "script/modx-mail.php",
    "content": "<?php\n\n$method = $_SERVER['REQUEST_METHOD'];\n$c = true;\n\nif ( $method === 'POST' ) {\n\n  $project_name = $modx->getOption('site_name');\n  $admin_email  = $modx->getOption('emailsender');\n  $form_subject = \"Заявка с сайта \" . $modx->getOption('site_name') . \"\";\n\n  foreach ( $_POST as $key => $value ) {\n    if ( $value != \"\" && $key != \"project_name\" && $key != \"admin_email\" && $key != \"form_subject\" ) {\n      $message .= \"\n      \" . ( ($c = !$c) ? '<tr>':'<tr style=\"background-color: #f8f8f8;\">' ) . \"\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>\n      </tr>\n      \";\n    }\n  }\n} else if ( $method === 'GET' ) {\n\n  $project_name = trim($_GET[\"project_name\"]);\n  $admin_email  = trim($_GET[\"admin_email\"]);\n  $form_subject = trim($_GET[\"form_subject\"]);\n\n  foreach ( $_GET as $key => $value ) {\n    if ( $value != \"\" && $key != \"project_name\" && $key != \"admin_email\" && $key != \"form_subject\" ) {\n      $message .= \"\n      \" . ( ($c = !$c) ? '<tr>':'<tr style=\"background-color: #f8f8f8;\">' ) . \"\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td>\n        <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td>\n      </tr>\n      \";\n    }\n  }\n};\n\n$message = \"<table style='width: 100%;'>$message</table>\";\n\nfunction adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };\n\n$headers = \"MIME-Version: 1.0\" . \"\\r\\n\" .\n\"Content-Type: text/html; charset=utf-8\" . \"\\r\\n\" .\n\"From: \" . adopt($project_name) . \" <\" . $admin_email . \">\" . \"\\r\\n\" .\n\"Reply-To: \" . $admin_email . \"\" . \"\\r\\n\";\n\nmail($admin_email, adopt($form_subject), $message, $headers );\n"
  },
  {
    "path": "script/script.js",
    "content": "const mailPath = './mail.php'\n\ndocument.querySelectorAll('.uniForm').forEach( (e) => {\n\n  e.addEventListener('submit', function(e) {\n\n    let th      = this,\n        params  = new FormData(this),\n        request = new XMLHttpRequest()\n\n    request.open('POST', mailPath, true)\n    request.send(params)\n\n    request.onreadystatechange = function() {\n      if (this.readyState == 4 && this.status == 200) {\n        setTimeout(function() { th.reset() }, 1000)\n        alert('Thank you!')\n      }\n    }\n\n    e.preventDefault()\n\n  })\n\n})\n"
  }
]