Skip to content

Instantly share code, notes, and snippets.

@seabrizz
Created September 23, 2016 21:53
Show Gist options
  • Save seabrizz/6c58843128942f5d52fe661b6350eea0 to your computer and use it in GitHub Desktop.
Save seabrizz/6c58843128942f5d52fe661b6350eea0 to your computer and use it in GitHub Desktop.
form for send eMail
<?php
$method = $_SERVER['REQUEST_METHOD'];
//Script Foreach
$c = true;
if ( $method === 'POST' ) {
$project_name = trim($_POST["project_name"]);
$admin_email = trim($_POST["admin_email"]);
$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"]);
$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 .
'Reply-To: '.$admin_email.'' . PHP_EOL;
mail($admin_email, adopt($form_subject), $message, $headers );
html:
<form id="call-back">
<input type="hidden" name="project_name" value="site">
<input type="hidden" name="admin_email" value="your e-mail">
<input type="hidden" name="form_subject" value="theme mail">
<span>call back</span>
<input type="text" name="Name" placeholder="your name" maxlength="45" required>
<input type="email" name="e-mail" placeholder="exaple@mail.com" required>
<input type="tel" name="Telefone" placeholder="+38 (0__) ___ __ __" maxlength="20" required>
<textarea type="text" name="Content" placeholder="input text"></textarea>
<button class="bttn">call back</button>
</form>
js:
$("#call-back").submit(function() { //Change
var th = $(this);
$.ajax({
type: "POST",
url: "mail.php", //Change
data: th.serialize()
}).done(function() {
alert("Ваша заявка прийнята.");
setTimeout(function() {
// Done Functions
th.trigger("reset");
$.magnificPopup.close();
}, 1000);
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment