Mam problem ze skryptem kontaktu. Mianowicie znalazłem coś takiego: http://www.hongkiat.com/blog/ajax-html5-cs...m-tutorial/#top
Cały problem polega na tym, że są problemy z polskimi znakami w mailach które dochodzą na skrzynkę. Podejrzewam ze trzeba ustawic kodowanie dla wysyłanych wiadomości, tylko nie wiem jak to zrobic.
Skrypt wyglada w ten sposób:
Kod
<?php
error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP
//If the form is submitted
if(isset($_POST['submitted'])) {
// require a name from user
if(trim($_POST['contactName']) === '') {
$nameError = 'Podaj imię i nazwisko!';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
// need valid email
if(trim($_POST['email']) === '') {
$emailError = 'Zapomniałeś wpisać swój adres e-mail.';
$hasError = true;
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
$emailError = 'Wprowadzono nieprawidłowy adres e-mail.';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
// we need at least some content
if(trim($_POST['comments']) === '') {
$commentError = 'Zapomniałeś wpisać wiadomość!';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
// upon no failure errors let's email now!
if(!isset($hasError)) {
$emailTo = 'jakisadres@jakisadres.pl';
$subject = 'Otrzymano wiadomość od '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Imię i nazwisko $name \n\ne-mail: $email \n\nWiadomośc: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta content="pl" http-equiv="Content-Language" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML5/CSS Ajax Contact Form with jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- @begin contact -->
<div id="contact" class="section">
<div class="container content">
<?php if(isset($emailSent) && $emailSent == true) { ?>
<p class="info">Twój e-mail został wysłany.</p>
<?php } else { ?>
<div class="desc">
<h2>Formularz kontaktowy</h2>
<p class="desc">Please use the contact form below to send us any information we may need. It is required you place an e-mail, although if you do not need us to respond feel free to input noreply@yoursite.com.</p>
</div>
<div id="contact-form">
<?php if(isset($hasError) || isset($captchaError) ) { ?>
<p class="alert">Błąd złożenia formularza</p>
<?php } ?>
<form id="contact-us" action="contact.php" method="post">
<div class="formblock">
<label class="screen-reader-text">Imię i nazwisko</label>
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" placeholder="Imię i nazwisko:" />
<?php if($nameError != '') { ?>
<br /><span class="error"><?php echo $nameError;?></span>
<?php } ?>
</div>
<div class="formblock">
<label class="screen-reader-text">e-mail</label>
<input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="txt requiredField email" placeholder="wpisz e-mail:" />
<?php if($emailError != '') { ?>
<br /><span class="error"><?php echo $emailError;?></span>
<?php } ?>
</div>
<div class="formblock">
<label class="screen-reader-text">Wiadomość</label>
<textarea name="comments" id="commentsText" class="txtarea requiredField" placeholder="Treść wiadomości ..."><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
<?php if($commentError != '') { ?>
<br /><span class="error"><?php echo $commentError;?></span>
<?php } ?>
</div>
<button name="submit" type="submit" class="subbutton">Wyślij !</button>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<?php } ?>
</div>
</div><!-- End #contact -->
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
$('form#contact-us').submit(function() {
$('form#contact-us .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if($.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error">Wpisz +labelText+'.</span>');
$(this).addClass('inputError');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error">Sorry! You\'ve entered an invalid '+labelText+'.</span>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contact-us').slideUp("fast", function() {
$(this).before('<p class="tick"><strong>Thanks!</strong> Your email has been delivered. Huzzah!</p>');
});
});
}
return false;
});
});
//-->!]]>
</script>
</body>
</html>
error_reporting(E_ALL ^ E_NOTICE); // hide all basic notices from PHP
//If the form is submitted
if(isset($_POST['submitted'])) {
// require a name from user
if(trim($_POST['contactName']) === '') {
$nameError = 'Podaj imię i nazwisko!';
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
// need valid email
if(trim($_POST['email']) === '') {
$emailError = 'Zapomniałeś wpisać swój adres e-mail.';
$hasError = true;
} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
$emailError = 'Wprowadzono nieprawidłowy adres e-mail.';
$hasError = true;
} else {
$email = trim($_POST['email']);
}
// we need at least some content
if(trim($_POST['comments']) === '') {
$commentError = 'Zapomniałeś wpisać wiadomość!';
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
// upon no failure errors let's email now!
if(!isset($hasError)) {
$emailTo = 'jakisadres@jakisadres.pl';
$subject = 'Otrzymano wiadomość od '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Imię i nazwisko $name \n\ne-mail: $email \n\nWiadomośc: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
// set our boolean completion value to TRUE
$emailSent = true;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta content="pl" http-equiv="Content-Language" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML5/CSS Ajax Contact Form with jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- @begin contact -->
<div id="contact" class="section">
<div class="container content">
<?php if(isset($emailSent) && $emailSent == true) { ?>
<p class="info">Twój e-mail został wysłany.</p>
<?php } else { ?>
<div class="desc">
<h2>Formularz kontaktowy</h2>
<p class="desc">Please use the contact form below to send us any information we may need. It is required you place an e-mail, although if you do not need us to respond feel free to input noreply@yoursite.com.</p>
</div>
<div id="contact-form">
<?php if(isset($hasError) || isset($captchaError) ) { ?>
<p class="alert">Błąd złożenia formularza</p>
<?php } ?>
<form id="contact-us" action="contact.php" method="post">
<div class="formblock">
<label class="screen-reader-text">Imię i nazwisko</label>
<input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" placeholder="Imię i nazwisko:" />
<?php if($nameError != '') { ?>
<br /><span class="error"><?php echo $nameError;?></span>
<?php } ?>
</div>
<div class="formblock">
<label class="screen-reader-text">e-mail</label>
<input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="txt requiredField email" placeholder="wpisz e-mail:" />
<?php if($emailError != '') { ?>
<br /><span class="error"><?php echo $emailError;?></span>
<?php } ?>
</div>
<div class="formblock">
<label class="screen-reader-text">Wiadomość</label>
<textarea name="comments" id="commentsText" class="txtarea requiredField" placeholder="Treść wiadomości ..."><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
<?php if($commentError != '') { ?>
<br /><span class="error"><?php echo $commentError;?></span>
<?php } ?>
</div>
<button name="submit" type="submit" class="subbutton">Wyślij !</button>
<input type="hidden" name="submitted" id="submitted" value="true" />
</form>
</div>
<?php } ?>
</div>
</div><!-- End #contact -->
<script type="text/javascript">
<!--//--><![CDATA[//><!--
$(document).ready(function() {
$('form#contact-us').submit(function() {
$('form#contact-us .error').remove();
var hasError = false;
$('.requiredField').each(function() {
if($.trim($(this).val()) == '') {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error">Wpisz +labelText+'.</span>');
$(this).addClass('inputError');
hasError = true;
} else if($(this).hasClass('email')) {
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
if(!emailReg.test($.trim($(this).val()))) {
var labelText = $(this).prev('label').text();
$(this).parent().append('<span class="error">Sorry! You\'ve entered an invalid '+labelText+'.</span>');
$(this).addClass('inputError');
hasError = true;
}
}
});
if(!hasError) {
var formInput = $(this).serialize();
$.post($(this).attr('action'),formInput, function(data){
$('form#contact-us').slideUp("fast", function() {
$(this).before('<p class="tick"><strong>Thanks!</strong> Your email has been delivered. Huzzah!</p>');
});
});
}
return false;
});
});
//-->!]]>
</script>
</body>
</html>