Vytvoril som si na stranke formular ale mam problem ze mi neodosle, nedoruci obsah formulara na dany email. Robil som nejake testy a vysledok je takyto:
1) emailova adresa na ktoru sa ma odoslat obsah je na ...@gmail.com
2) po vyplneni vsetkych poli formulara (zadani emailovej adresy ...@stranka.sk (emailova adresa je sucastou adresy webu
http://www.stranka.sk), obsah formulara sa odosle a aj doruci na ...@gmail.com
3) po vyplneni vsetkych poli formulara (zadani emailovej adresy ...@azet.sk, ...@gmail.com (emailova adresa nieje sucastou adresy webu
http://www.stranka.sk), obsah formulara sa odosle ale nedoruci sa na ...@gmail.com
testovaci web je umiestneny na
http://1.navrchol.sk/objednavka.html Vie mi niekdo povedat kde moze byt problem?objednavka.html
Kód:
<form name="contactform" method="post" action="send_form_email.php">
<table width="450px">
<tr>
<td valign="top">
<label for="first_name">Meno *</label>
</td>
<td valign="top"">
<input type="text" name="first_name" maxlength="50" size="30" style="border: 1px solid black">
</td>
</tr>
<tr>
<td valign="top"">
<label for="last_name">Priezvisko *</label>
</td>
<td valign="top">
<input type="text" name="last_name" maxlength="50" size="30" style="border: 1px solid black">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email *</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="80" size="30" style="border: 1px solid black">
</td>
</tr>
<tr>
<td valign="top">
<label for="telephone">Telefón</label>
</td>
<td valign="top">
<input type="text" name="telephone" maxlength="30" size="30" style="border: 1px solid black">
</td>
</tr>
<tr>
<td valign="top">
<label for="comments">Vaša objednávka *</label>
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="30" rows="6" style="border: 1px solid black"></textarea>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center">
<input type="submit" value="Odoslať objednávku">
</td>
</tr>
</table>
</form>
send_form_email.php
Kód:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "marek.adamec@gmail.com";
$email_subject = "Objednávka na prepravu tovaru - Grandimport.sk";
function died($error) {
// your error code can go here
echo "Je nam velmi luto, ale doslo k chybe. ";
echo "Chyby sa zobrazia nizsie.<br /><br />";
echo $error."<br /><br />";
echo "Vratte sa spat a opravte chyby.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('Je nam velmi luto, ale doslo k chybe.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'Neplatna alebo zle zadana emailova adresa.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'Chyba meno.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'Chyba priezvisko<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'Chyba obsah objednavky.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Objednávka odoslana z formulára na Grandimport.sk.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Meno: ".clean_string($first_name)."\n";
$email_message .= "Priezvisko: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telefón: ".clean_string($telephone)."\n";
$email_message .= "Objednávka: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
Objednavka odoslana.
<?php
}
?>