├── .gitignore
├── readme.md
└── script
├── script.js
├── index.html
├── mail.php
└── modx-mail.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /**/node_modules/
2 | /dist/
3 | /.git/
4 | /app/css/
5 | /**/_backstage
6 | /**/package-lock.json
7 | /**/Thumbs.db
8 | /**/*.DS_Store
9 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
Universal PHP Mail Feedback Script
2 |
3 | How to use uniMail
4 |
5 |
6 | - Connect
script.js file to your project and Specify location mailPath in this file
7 | - Add
uniForm class to the desired <form> tags in HTML (like index.html example)
8 | - Add Hidden Required Fields to your forms in HTML (like index.html example)
9 | - Add any set of fields to your forms in HTML (like index.html example)
10 | - Done!
11 |
12 |
--------------------------------------------------------------------------------
/script/script.js:
--------------------------------------------------------------------------------
1 | const mailPath = './mail.php'
2 |
3 | document.querySelectorAll('.uniForm').forEach( (e) => {
4 |
5 | e.addEventListener('submit', function(e) {
6 |
7 | let th = this,
8 | params = new FormData(this),
9 | request = new XMLHttpRequest()
10 |
11 | request.open('POST', mailPath, true)
12 | request.send(params)
13 |
14 | request.onreadystatechange = function() {
15 | if (this.readyState == 4 && this.status == 200) {
16 | setTimeout(function() { th.reset() }, 1000)
17 | alert('Thank you!')
18 | }
19 | }
20 |
21 | e.preventDefault()
22 |
23 | })
24 |
25 | })
26 |
--------------------------------------------------------------------------------
/script/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | uniMail
6 |
7 |
8 |
9 |
10 |
27 |
28 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/script/mail.php:
--------------------------------------------------------------------------------
1 | $value ) {
13 | if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
14 | $message .= "
15 | " . ( ($c = !$c) ? '':'
' ) . "
16 | | $key |
17 | $value |
18 |
19 | ";
20 | }
21 | }
22 | } else if ( $method === 'GET' ) {
23 |
24 | $project_name = trim($_GET["project_name"]);
25 | $admin_email = trim($_GET["admin_email"]);
26 | $form_subject = trim($_GET["form_subject"]);
27 |
28 | foreach ( $_GET as $key => $value ) {
29 | if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
30 | $message .= "
31 | " . ( ($c = !$c) ? '':'
' ) . "
32 | | $key |
33 | $value |
34 |
35 | ";
36 | }
37 | }
38 | };
39 |
40 | $message = "";
41 |
42 | function adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };
43 |
44 | $headers = "MIME-Version: 1.0" . "\r\n" .
45 | "Content-Type: text/html; charset=utf-8" . "\r\n" .
46 | "From: " . adopt($project_name) . " <" . $admin_email . ">" . "\r\n" .
47 | "Reply-To: " . $admin_email . "" . "\r\n";
48 |
49 | mail($admin_email, adopt($form_subject), $message, $headers );
50 |
--------------------------------------------------------------------------------
/script/modx-mail.php:
--------------------------------------------------------------------------------
1 | getOption('site_name');
9 | $admin_email = $modx->getOption('emailsender');
10 | $form_subject = "Заявка с сайта " . $modx->getOption('site_name') . "";
11 |
12 | foreach ( $_POST as $key => $value ) {
13 | if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
14 | $message .= "
15 | " . ( ($c = !$c) ? '':'
' ) . "
16 | | $key |
17 | $value |
18 |
19 | ";
20 | }
21 | }
22 | } else if ( $method === 'GET' ) {
23 |
24 | $project_name = trim($_GET["project_name"]);
25 | $admin_email = trim($_GET["admin_email"]);
26 | $form_subject = trim($_GET["form_subject"]);
27 |
28 | foreach ( $_GET as $key => $value ) {
29 | if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
30 | $message .= "
31 | " . ( ($c = !$c) ? '':'
' ) . "
32 | | $key |
33 | $value |
34 |
35 | ";
36 | }
37 | }
38 | };
39 |
40 | $message = "";
41 |
42 | function adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };
43 |
44 | $headers = "MIME-Version: 1.0" . "\r\n" .
45 | "Content-Type: text/html; charset=utf-8" . "\r\n" .
46 | "From: " . adopt($project_name) . " <" . $admin_email . ">" . "\r\n" .
47 | "Reply-To: " . $admin_email . "" . "\r\n";
48 |
49 | mail($admin_email, adopt($form_subject), $message, $headers );
50 |
--------------------------------------------------------------------------------