Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HTML
- <div class="form">
- <div class="new-form">
- <form class="ajax-contact-form" action="" method="post" name="commentform" id="commentform" _lpchecked="1">
- <input type="text" name="author" id="author" value="" size="25" placeholder="Your name">
- <input type="text" name="email" id="email" value="" size="25" placeholder="Email">
- <textarea name="message" id="comment" cols="48" rows="8" placeholder="What are you needs? Include as much info as possible."></textarea>
- <input name="submit" type="submit" id="submit" value="Send" class="">
- </form>
- </div>
- </div>
- JS
- $(".ajax-contact-form").submit(function() {
- var str = $(this).serialize();
- $.ajax({
- type: "POST",
- url: "contact.php",
- data: str,
- success: function(msg) {
- if(msg == 'OK') {
- result = '<p>Ваш заказ принят</p>';
- $(".fields").hide();
- } else {
- result = msg;
- }
- $('.note').html(result);
- }
- });
- return false;
- });
- PHP
- <?php
- $post = (!empty($_POST)) ? true : false;
- if($post)
- {
- $email = trim($_POST['email']);
- $author = htmlspecialchars($_POST['author']);
- $email = htmlspecialchars($_POST['email']);
- $message = htmlspecialchars($_POST['message']);
- $error = '';
- if(!$author)
- {
- $error .= 'Пожалуйста введите ваше имя<br />';
- }
- // Проверка телефона
- function ValidateTel($valueTel)
- {
- $regexTel = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
- if($valueTel == "") {
- return false;
- } else {
- $string = preg_replace($regexTel, "", $valueTel);
- }
- return empty($string) ? true : false;
- }
- if(!$email)
- {
- $error .= "Пожалуйста введите email<br />";
- }
- if($email && !ValidateTel($email))
- {
- $error .= "Введите корректный email<br />";
- }
- if(!$error)
- // (length)
- if(!$message || strlen($message) < 1)
- {
- $error .= "Введите ваше сообщение<br />";
- }
- if(!$error)
- {
- $author_tema = "=?utf-8?b?". base64_encode($author) ."?=";
- $subject ="Новая заявка с сайта precisecreative";
- $subject1 = "=?utf-8?b?". base64_encode($subject) ."?=";
- /*
- $message ="\n\nСообщение: ".$message."\n\nИмя: " .$author."\n\nТелефон: ".$tel."\n\n";
- */
- $message1 ="\n\nИмя: ".$author."\n\nТелефон: " .$tel."\n\nE-mail: " .$email."\n\nСообщение: ".$message."\n\n";
- $header = "Content-Type: text/plain; charset=utf-8\n";
- $header .= "From: Новая заявка <[email protected]>\n\n";
- $mail = mail("[email protected]", $subject1, iconv ('utf-8', 'windows-1251', $message1), iconv ('utf-8', 'windows-1251', $header));
- if($mail)
- {
- echo 'OK';
- }
- }
- else
- {
- echo '<div class="notification_error">'.$error.'</div>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement