<?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $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) { $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"> <div class="form-group"> <div class="col-sm-10"> <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>";?> </div> </div> <div class="form-group"> <div class="col-sm-10"> <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>";?> </div> </div> <div class="form-group"> <div class="col-sm-10"> <?php echo "<p class='text-danger'>$errMessage</p>";?> </div> </div> <div class="form-group"> <div class="col-sm-10"> <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> </div> <div class="form-group"> <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> </div> <div class="form-group"> <div class="col-sm-10 col-sm-offset-0"> <?php echo $result; ?> </div> </div> </form>
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.