| Autor | Zpráva | ||
|---|---|---|---|
| sidlo Profil |
#1 · Zasláno: 8. 2. 2011, 22:47:09 · Upravil/a: sidlo
Ano vím, stokrát opakované téma, ale ani po třech dnech, co jsem přečetl všechny diskuze a FAQ na toho téma, se mi stále nepodařilo to zprovoznit. Můžete mi s tím prosím vás pomoct? Předem díky
Je to rezervační formulář do restaurace - jeden mail restauraci a jeden zákazníkovi Vymazal jsem z toho všechny pokusy (např. function autoUTF z FAQ) <?php
header("Content-Type: text/html; charset=UTF-8");
if(!$_POST) exit;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$date = $_POST['date'];
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];
$person = $_POST['person'];
if(trim($name) == '') {
echo '<div class="error_message">You must enter your name.</div>';
exit();
}
//TADY JSOU DALŠÍ NEPODSTATNÝ HLÁŠKY PO OVĚŘENÍ OBSAHU
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "skvor.jan@gmail.com";
$subject = 'Rezervace od ' . $name . '';
$customer_subject = 'Vaše rezervace';
$body = "Vaše rezervace byla odeslána s těmito údaji\r\n\nJméno: $name \r\nEmail: $email \r\nTelefon: $phone \r\nDatum: $date \r\nČas: $time1 - $time2 \r\nPočet osob: $person \r\n Komentář: $comments";
$customer_body = "Vaše rezervace byla odeslána s těmito údaji\r\n\nJméno: $name \r\nEmail: $email\r\nTelefon: $phone \r\nDatum: $date \r\nČas: $time1 - $time2 \r\nPočet osob: $person \r\n Komentář: $comments";
$msg = $body;
$headers = "From: $email\r\n";
$headers = "Reply-To: $email\r\n";
$headers = "Return-Path: $email\r\n";
$headers .= "Content-Type: text/html; charset=utf-8";
$customer_msg = $customer_body;
if((mail($address, $subject, $msg, $headers)) && (mail($email, $customer_subject, $customer_msg, $headers))) {
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3>Reservation Sent Successfully.</h3>";
echo "<p>Thank you <strong>$name</strong>, if there is some problem, we will get back to you as soon as possible.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo '<div class="error_message">ERROR! Try it later or use phone.</div>';
}
}
function isEmail($email) {
return(preg_match("/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i",$email));
}
//A TADY NEPODSTATNÝ OVĚŘOVACÍ FCE
?> |
||
| Radek Cvek Profil |
#2 · Zasláno: 8. 2. 2011, 23:57:49
Schválně jsem se díval do FAQ a ta hlavička mailu ($headers) tam vypadá úplně jinak - zkuste to přesně podle tohoto.
|
||
| Davex Profil |
#3 · Zasláno: 9. 2. 2011, 00:00:02
Asi by bylo dobré, zopakovat si základy PHP a spojování řetězců. Pro konec řádku v hlavičce by bylo dobré použít konstantu PHP_EOL a přidat ho i na poslední řádek.
$headers = "From: $email" . PHP_EOL; $headers .= "Reply-To: $email" . PHP_EOL; $headers .= "Return-Path: $email" . PHP_EOL; $headers .= "Content-Type: text/html; charset=\"utf-8\"" . PHP_EOL; Dále by tam neměla chybět verze MIME a někdy pomůže i definovat způsob kódování dat. $headers .= "MIME-Version: 1.0" . PHP_EOL . "Content-Transfer-Encoding: 8bit" . PHP_EOL; Co prosím není v PHP FAQ srozumitelné? Můžeme to upřesnit. |
||
| sidlo Profil |
#4 · Zasláno: 9. 2. 2011, 01:18:26
Díky za upozornění na PHP_EOL. Ale to pořád nevyřešilo můj problém..
Nejde o to, že by to bylo vysvětlené v php faq nesrozumitelně, ale to řešení, které tam je popsané, mi stejně nefunguje. |
||
| Alphard_ Profil * |
#5 · Zasláno: 9. 2. 2011, 01:24:00
[#4] sidlo
Řešení uvedené v FAQ obyvkle funguje. Nevylučuji, že je u vás něco nestandardního, ale není to pravděpodobné. Dejte sem ukázku upravenou přesně podle FAQ, jestli to nepůjde, zkusím najít chybu. |
||
| sidlo Profil |
#6 · Zasláno: 9. 2. 2011, 20:33:31
Tak tady je celý kód, předem díky za tvůj čas.
<?php
header("Content-Type: text/html; charset=UTF-8");
if(!$_POST) exit;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];
$date = $_POST['date'];
$time1 = $_POST['time1'];
$time2 = $_POST['time2'];
$person = $_POST['person'];
if(trim($name) == '') {
echo '<div class="error_message">You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Please enter a valid phone number.</div>';
exit();
} else if(!isName($name)) {
echo '<div class="error_message">Your name can contain only letters.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Please enter an valid e-mail address.<br /><strong>E.g. info@nasikmeplose.cz</strong></div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Phone number can only contain digits.</div>';
exit();
} else if(!isDate($date)) {
echo '<div class="error_message">Please enter a valid date.<br /><strong>E.g. 25.3.2011</strong></div>';
exit();
}
else if(!isTime1($time1)) {
echo '<div class="error_message">Please enter a valid time.<br />It must be in half an hour intervals. <strong>E.g. 15:00, 15:30, 16:00..</strong></div>';
exit();
} else if(!isTime2($time2)) {
echo '<div class="error_message">Please enter a valid time.<br />It must be in half an hour intervals. <strong>E.g. 16:00, 16:30, 17:00..</strong></div>';
exit();
} else if(!isPerson($person)) {
echo '<div class="error_message">Please enter number of persons from 1 to 49.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
/* *************** diskuse.jakpsatweb.cz *** PHP FAQ ********************** */
function autoUTF($s)
{
if (preg_match('#[\x80-\x{1FF}\x{2000}-\x{3FFF}]#u', $s)) // detect UTF-8
{
return $s;
}
elseif (preg_match('#[\x7F-\x9F\xBC]#', $s)) // detect WINDOWS-1250
{
return iconv('WINDOWS-1250', 'UTF-8', $s);
}
else // assume ISO-8859-2
{
return iconv('ISO-8859-2', 'UTF-8', $s);
}
}
function cs_mail($address, $subject, $msg, $head = "")
{
$subject = "=?utf-8?B?".base64_encode(autoUTF($subject))."?=";
$head .= "MIME-Version: 1.0\r\n";
$head = "From: $email" . PHP_EOL;
$head .= "Reply-To: $email" . PHP_EOL;
$head .= "Return-Path: $email" . PHP_EOL;
$head .= "Content-Type: text/html; charset=\"utf-8\"" . PHP_EOL;
$head .= "MIME-Version: 1.0" . PHP_EOL . "Content-Transfer-Encoding: base64" . PHP_EOL;
$msg = base64_encode(autoUTF($msg));
return mail($address, $subject, $msg, $head);
}
/* ********************************************************************** ** */
$address = "skvor.jan@gmail.com";
$subject = 'Rezervace od ' . $name . '';
$customer_subject = 'Vaše rezervace';
$body = "Vaše rezervace byla odeslána s těmito údaji\r\n\nJméno: $name \r\nEmail: $email \r\nTelefon: $phone \r\nDatum: $date \r\nČas: $time1 - $time2 \r\nPočet osob: $person \r\n Komentář: $comments";
$customer_body = "Vaše rezervace byla odeslána s těmito údaji\r\n\nJméno: $name \r\nEmail: $email\r\nTelefon: $phone \r\nDatum: $date \r\nČas: $time1 - $time2 \r\nPočet osob: $person \r\n Komentář: $comments";
$msg = $body;
$customer_msg = $customer_body;
if((cs_mail($address, $subject, $msg, $head)) && (mail($email, $customer_subject, $customer_msg, $headers))) {
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h3>Reservation Sent Successfully.</h3>";
echo "<p>Thank you <strong>$name</strong>, if there is some problem, we will get back to you as soon as possible.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo '<div class="error_message">ERROR! Try it later or use phone.</div>';
}
}
function isName($name) {
return(preg_match("/^[^0-9]+$/",$name));
}
function isEmail($email) {
return(preg_match("/^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i",$email));
}
function isDate($date) {
return(preg_match("/^(([0-2]?[0-9])|(3[01])).((0?[0-9])|(1[012])).20[0-9]{2}$/",$date));
}
function isTime1($time1) {
return(preg_match("/^(1[2-9]|2[0-3]):(00|30)$/",$time1));
}
function isTime2($time2) {
return(preg_match("/^(1[2-9]|2[0-3]):(00|30)$/",$time2));
}
function isPerson($person) {
return(preg_match("/^([1-9]|[1-4][0-9])$/",$person));
}
?> |
||
| Davex Profil |
#7 · Zasláno: 9. 2. 2011, 23:12:18 · Upravil/a: Davex
1) Funkce
cs_mail() se volá jen jednou. Zákazníkovi se e-mail stále odesílá funkcí mail().
2) Je stránka s formulářem také v kódování UTF-8? Krom toho vypadá funkce cs_mail() ve FAQ jinak, ale na diakritiku to nebude mít vliv. Vzniká tam jiná chyba.
|
||
| Radek Cvek Profil |
#8 · Zasláno: 9. 2. 2011, 23:37:04
Co přesně nefunguje? U head je zase přemazaný ten první řádek. Mě to poslalo i se správnou diakritikou. Není tu ten formulář. Jak píše Davex - tam by mohla být chyba.
|
||
| sidlo Profil |
#9 · Zasláno: 10. 2. 2011, 00:21:22
Ano, zapomněl jsem dopsat, že cs_mail zatim volám jenom jednou a porovnávám výsledky, ale zatim mi na gmail i seznam dojde: Vaše rezervace byla odeslána s těmito údaji Jméno: škvor jan Email: skvor.sidlo@seznam.cz Telefon: 123456789 Datum: 25.11.2012 Čas: 15:00 - 18:00 Počet osob: 12 Komentář: ĹľĂĹľala
Smazal jsem řádek, který tam byl navíc $head .= "MIME-Version: 1.0\r\n"; A formulář mám taky v utf-8, kód zde. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Reservation</title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript" src="js/jquery.jigowatt.js"></script> </head> <body> <div id="contact"> <h3>ON LINE RESERVATION FORM</h3> <p style="text-align: justify;">Through this online reservation form, please send reservations only more than <strong>12 hours in advance</strong>.</p> <div id="message"></div> <form method="post" action="contact.php" name="contactform" id="contactform"> <fieldset> <label for=name><span class="required">*</span> Your Name</label> <input name="name" type="text" id="name" size="15" value="" /> <br /> <label for=email><span class="required">*</span> Your Email</label> <input name="email" type="text" id="email" size="15" value="" /> <br /> <label for=phone><span class="required">*</span> Your Phone</label> <input name="phone" type="text" id="phone" size="15" value="" /> <br /> <label for=date><span class="required">*</span> Date <span class="shadow">(23.2.2011)</span></label> <input name="date" type="text" id="date" size="15" value="" /> <br /> <label for=time1><span class="required">*</span> Time from <span class="shadow">(16:30)</span></label> <input name="time1" type="text" id="time1" size="15" value="" /> <br /> <label for=time2><span class="required">*</span> Time just about till <span class="shadow">(18:00)</span></label> <input name="time2" type="text" id="time2" size="15" value="" /> <br /> <label for=person><span class="required">*</span> Number of persons</label> <input name="person" type="text" id="person" size="15" value="" /> <br /> <label for=comments>Your comments</label> <textarea name="comments" cols="15" rows="1" id="comments"></textarea> <input type="submit" class="submit" id="submit" value="Submit" /> </fieldset> </form> </div> </body> </html> |
||
| Alphard_ Profil * |
#10 · Zasláno: 10. 2. 2011, 07:18:47
sidlo:
„Vaše rezervace byla odeslána s těmito údaji Jméno: škvor jan Email: skvor.sidlo@seznam.cz Telefon: 123456789 Datum: 25.11.2012 Čas: 15:00 - 18:00 Počet osob: 12 Komentář: ĹľĂĹľala“ Jak vidíte, diakritika i stringů v PHP bloku je správná, to naznačuje, že se vám kombinují 2 různá kódování. Funkce autoUTF() má své meze. Jsou ty sobory uložené ve stejném kódování a sice v utf-8? Funkci cs_mail() jste upravil (nebo rozbil) do nesprávné podoby. Proměnná $email (nedefinovaná jako globální) by v tom kontextu neměla být vidět, nebo to snad funguje? |
||
| sidlo Profil |
#11 · Zasláno: 10. 2. 2011, 10:24:25
Chytrý :) Vůbec mě nenapadlo zkontrolovat uložení souboru v utf-8. Už to s fcí autoUTF() funguje.
Děkuju všem moc za pomoc. |
||
|
Časová prodleva: 15 let
|
|||
0