Witam mam sobie na stronie taki formularz kontaktowy:
<?php
if (isset($_POST["submit"])) { $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = intval($_POST['human']); $to = 'adres_odbiorcy';
$subject = 'Wiadomość z nazwa_strony ';
$body = "OD: $name\n Odpowiedź proszę wysłać na ten adres e-mail: $email\n Treść:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Uzupełnij to pole';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Wpisz poprawny adres email';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Wpisz treść wiadomości';
}
//Check if simple anti-bot test is correct
if ($human !== 15) {
$errHuman = 'Wpisz poprawny wynik dodawania';
}
// If there are no errors, send the email
if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
if (mail ($to, $subject, $body, $from)) { $result='<div class="alert alert-success">Dziękuję! Odpowiem w możliwie najkrótszym czasie</div>';
} else {
$result='<div class="alert alert-danger">Przepraszam nie udało się wysłać wiadomości! Sprawdź czy poprawnie wypełniłeś/aś formularz</div>';
}
}
}
?>
oraz kod formularz w html
<form class="" method="post" action="index.php"> <input type="text" class="form-control" id="name" name="name" placeholder="Jak się nazywasz?" value="<?php echo htmlspecialchars($_POST['name']); ?>">
<?php echo "<p class='text-danger'>$errName
</p>";?>
<input type="email" class="form-control" id="email" name="email" placeholder="Twój adres email" value="<?php echo htmlspecialchars($_POST['email']); ?>">
<?php echo "<p class='text-danger'>$errEmail
</p>";?>
<textarea class="form-control" rows="4" name="message" placeholder="Wpisz treść wiadomości"><?php echo htmlspecialchars($_POST['message']);?></textarea> <?php echo "<p class='text-danger'>$errMessage
</p>";?>
<input type="text" class="form-control" id="human" name="human" placeholder="Wpisz poprawny wynik dodawania: 10+5=?"> <?php echo "<p class='text-danger'>$errHuman
</p>";?>
<div class="col-sm-10 col-sm-offset-0"> <input id="submit" name="submit" type="submit" value="Wyślij zapytanie" class="btn btn-primary"> <div class="col-sm-10 col-sm-offset-0"> <?php echo $result; ?>
Ogólnie formularz działa poprawnie ale mam problem z polem nadawcy!
W klientach pocztowych w polu nadawca jest podany adres serwera pocztowego a po kliknięciu na odpowiedz do wiadomość jest kierowana na ten właśnie adres.
Prosże o podpowiedź jak poprawnie zdefiniowaś pole From w takim formularzu.