Я хочу использовать эту контактную форму на своем веб-сайте. но при нажатии кнопки "Отправить" возникла ошибка. Я действительно не знаю, как это решить, но, судя по моим небольшим знаниям, это проблема с jquery, которая может пройти и получить ошибку. для меня очень важно решить эту проблему. это коды, которые вам понадобятся. спасибо за помощь и извините за мой плохой английский
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$name = ($_GET['name']) ? $_GET['name'] : $_POST['name'];
$email = ($_GET['email']) ?$_GET['email'] : $_POST['email'];
$message = ($_GET['message']) ?$_GET['message'] : $_POST['message'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email
if (!$name) $errors[count($errors)] = 'Please enter your name.';
if (!$email) $errors[count($errors)] = 'Please enter your email.';
if (!$message) $errors[count($errors)] = 'Please enter your message.';
//If the errors array is empty, send the mail
if (!$errors) {
// ====== Your mail here ====== //
$to = 'alireza.b1993@gmail.com';
// Sender
$from = $name . ' ';
//subject and the html message
$subject = 'Message from your website';
$message = '
Name:' . $name . '
Email:' . $email . '
Message:' . nl2br($message) . '
';
// Send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
// If the errors array has values
} else {}
// Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=utf-8" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>
Я хочу использовать эту контактную форму на своем веб-сайте. но при нажатии кнопки "Отправить" возникла ошибка. Я действительно не знаю, как это решить, но, судя по моим небольшим знаниям, это проблема с jquery, которая может пройти и получить ошибку. для меня очень важно решить эту проблему. это коды, которые вам понадобятся. спасибо за помощь и извините за мой плохой английский
php-код:
[code]//Retrieve form data. //GET - user submitted data using AJAX //POST - in case user does not support javascript, we'll use POST instead $name = ($_GET['name']) ? $_GET['name'] : $_POST['name']; $email = ($_GET['email']) ?$_GET['email'] : $_POST['email']; $message = ($_GET['message']) ?$_GET['message'] : $_POST['message'];
//flag to indicate which method it uses. If POST set it to 1 if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email if (!$name) $errors[count($errors)] = 'Please enter your name.'; if (!$email) $errors[count($errors)] = 'Please enter your email.'; if (!$message) $errors[count($errors)] = 'Please enter your message.';
//If the errors array is empty, send the mail if (!$errors) {
// ====== Your mail here ====== // $to = 'alireza.b1993@gmail.com';
// Sender $from = $name . ' ';
//subject and the html message $subject = 'Message from your website'; $message = '
// Send the mail $result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away if ($_POST) { if ($result) echo 'Thank you! We have received your message.'; else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that //ajax script can react accordingly //1 means success, 0 means failed } else { echo $result; }
// If the errors array has values } else {}
// Simple mail function with HTML header function sendmail($to, $subject, $message, $from) { $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=utf-8" . "\r\n"; $headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1; else return 0; }
?> [/code]
html-код:
[code]
name:
email :*
message :*
[/code]
а это js-код:
[code](function() { var animateSpeed=300; var emailReg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
// Validating
function validateName(name) { if (name.val()=='*') {name.addClass('validation-error',animateSpeed); return false;} else {name.removeClass('validation-error',animateSpeed); return true;} }
function validateEmail(email,regex) { if (!regex.test(email.val())) {email.addClass('validation-error',animateSpeed); return false;} else {email.removeClass('validation-error',animateSpeed); return true;} }
function validateMessage(message) { if (message.val()=='') {message.addClass('validation-error',animateSpeed); return false;} else {message.removeClass('validation-error',animateSpeed); return true;} }
$('#send').click(function() {
var result=true;
var name = $('input[name=name]'); var email = $('input[name=email]'); var message = $('textarea[name=message]');