Repository: agragregra/uniMail
Branch: master
Commit: 9a19ace3f292
Files: 6
Total size: 5.7 KB
Directory structure:
gitextract_gkea703z/
├── .gitignore
├── readme.md
└── script/
├── index.html
├── mail.php
├── modx-mail.php
└── script.js
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/**/node_modules/
/dist/
/.git/
/app/css/
/**/_backstage
/**/package-lock.json
/**/Thumbs.db
/**/*.DS_Store
================================================
FILE: readme.md
================================================
Universal PHP Mail Feedback Script
How to use uniMail
- Connect
script.js file to your project and Specify location mailPath in this file
- Add
uniForm class to the desired <form> tags in HTML (like index.html example)
- Add Hidden Required Fields to your forms in HTML (like index.html example)
- Add any set of fields to your forms in HTML (like index.html example)
- Done!
================================================
FILE: script/index.html
================================================
uniMail
================================================
FILE: script/mail.php
================================================
$value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '':'
' ) . "
| $key |
$value |
";
}
}
} else if ( $method === 'GET' ) {
$project_name = trim($_GET["project_name"]);
$admin_email = trim($_GET["admin_email"]);
$form_subject = trim($_GET["form_subject"]);
foreach ( $_GET as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '':'
' ) . "
| $key |
$value |
";
}
}
};
$message = "";
function adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };
$headers = "MIME-Version: 1.0" . "\r\n" .
"Content-Type: text/html; charset=utf-8" . "\r\n" .
"From: " . adopt($project_name) . " <" . $admin_email . ">" . "\r\n" .
"Reply-To: " . $admin_email . "" . "\r\n";
mail($admin_email, adopt($form_subject), $message, $headers );
================================================
FILE: script/modx-mail.php
================================================
getOption('site_name');
$admin_email = $modx->getOption('emailsender');
$form_subject = "Заявка с сайта " . $modx->getOption('site_name') . "";
foreach ( $_POST as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '':'
' ) . "
| $key |
$value |
";
}
}
} else if ( $method === 'GET' ) {
$project_name = trim($_GET["project_name"]);
$admin_email = trim($_GET["admin_email"]);
$form_subject = trim($_GET["form_subject"]);
foreach ( $_GET as $key => $value ) {
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) {
$message .= "
" . ( ($c = !$c) ? '':'
' ) . "
| $key |
$value |
";
}
}
};
$message = "";
function adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; };
$headers = "MIME-Version: 1.0" . "\r\n" .
"Content-Type: text/html; charset=utf-8" . "\r\n" .
"From: " . adopt($project_name) . " <" . $admin_email . ">" . "\r\n" .
"Reply-To: " . $admin_email . "" . "\r\n";
mail($admin_email, adopt($form_subject), $message, $headers );
================================================
FILE: script/script.js
================================================
const mailPath = './mail.php'
document.querySelectorAll('.uniForm').forEach( (e) => {
e.addEventListener('submit', function(e) {
let th = this,
params = new FormData(this),
request = new XMLHttpRequest()
request.open('POST', mailPath, true)
request.send(params)
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
setTimeout(function() { th.reset() }, 1000)
alert('Thank you!')
}
}
e.preventDefault()
})
})