Last active
March 20, 2018 13:06
-
-
Save AntonLitvin/4b72b18b5dd90816c4207ed6d40620b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form> | |
<!-- Hidden Required Fields --> | |
<input type="hidden" name="project_name" value="Site Name"> | |
<!-- <input type="hidden" name="admin_email" value="admin@mail.com"> --> | |
<input type="hidden" name="form_subject" value="Form Subject"> | |
<!-- END Hidden Required Fields --> | |
<input type="text" name="name" placeholder="You name..." required><br> | |
<input type="text" name="email" placeholder="You E-mail..." required><br> | |
<input type="text" name="phone" placeholder="You phone..."><br> | |
<button>Send</button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Ajax отправка форм | |
//Документация: http://api.jquery.com/jquery.ajax/ | |
$('#form1, #form2').on('submit', function(e) { | |
var $this = $(this); | |
e.preventDefault(); | |
$.ajax({ | |
type: 'POST', | |
url: 'mail.php', | |
data: $this.serialize() | |
}).done(function() { | |
alert('Спасибо за заявку!'); | |
//setTimeout(function() { | |
//$this.trigger('reset'); | |
//$.fancybox.close(); | |
//}, 1000); | |
success(); | |
}); | |
}); | |
function success() { | |
setTimeout(function() { | |
$('.loader').fadeIn(200); | |
setTimeout(function() { | |
$('.reply').fadeIn(300); | |
setTimeout(function() { | |
$('.loader').fadeOut(200); | |
$('#form1').trigger('reset'); | |
$('.reply').fadeOut(300); | |
$('.modal').fadeOut(300); | |
$('.overlay').fadeOut(300); | |
}, 3000); | |
}, 2000); | |
}, 500); | |
} | |
How to use uniMail | |
Include jQuery; | |
Include Ajax code from script.js; | |
Change Ajax selector in you JS; | |
Create HTML form with you form class; | |
Create HTML Hidden Required Fields with you values; | |
Change path to mail.php in you JS. | |
Done! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$method = $_SERVER['REQUEST_METHOD']; | |
//Script Foreach | |
$c = true; | |
if ( $method === 'POST' ) { | |
$project_name = trim($_POST["project_name"]); | |
// $admin_email = trim($_POST["admin_email"]); | |
$admin_email = 'info@my-site.com'; //Here write hosting email | |
$copy_email = 'copy1@gmail.com, copy2@gmail.com'; //copy | |
$form_subject = trim($_POST["form_subject"]); | |
foreach ( $_POST as $key => $value ) { | |
if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) { | |
$message .= " | |
" . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . " | |
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td> | |
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td> | |
</tr> | |
"; | |
} | |
} | |
} else if ( $method === 'GET' ) { | |
$project_name = trim($_GET["project_name"]); | |
// $admin_email = trim($_GET["admin_email"]); | |
$admin_email = 'info@my-site.com'; //Here write hosting email | |
$copy_email = 'copy1@gmail.com, copy2@gmail.com'; //copy | |
$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) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . " | |
<td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td> | |
<td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td> | |
</tr> | |
"; | |
} | |
} | |
} | |
$message = "<table style='width: 100%;'>$message</table>"; | |
function adopt($text) { | |
return '=?UTF-8?B?'.Base64_encode($text).'?='; | |
} | |
$headers = "MIME-Version: 1.0" . PHP_EOL . | |
"Content-Type: text/html; charset=utf-8" . PHP_EOL . | |
'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL . | |
'Cc:'.$copy_email.PHP_EOL . | |
'Reply-To: '.$admin_email.'' . PHP_EOL; | |
$sended = mail($admin_email, adopt($form_subject), $message, $headers ); | |
echo json_encode($sended); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment