Cześć
Stworzyłem na własne potrzeby stronkę internetową, na której umieściłem formularz kontaktowy. Chciałbym, aby po kliknięciu przycisku, zawartość formularza została wysłana na mój adres email. Wykorzystałem do tego skrypt .php, który dostosowałem do swoich potrzeb, jednak wiadomości nie dochodzą.
Nie jestem web devloperem, ale lubię robić wszystko sam, dlatego proszę o wyrozumiałość i możliwie jasne wskazówki, co robię nie tak.
Fragment kodu odpowiedzialnego za formularz wygląda tak:
<form name="contactform" action="sendform3.php" id="contactform" class="p-5 bg-white">
<div class="row form-group">
<div class="col-md-6 mb-3 mb-md-0">
<label class="text-black" for="fname">Imię</label>
<input type="text" id="fname" name="fname" class="form-control rounded-0">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">E-mail</label>
<input type="email" id="email" name="email" class="form-control rounded-0">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Temat</label>
<input type="subject" id="subject" name="subject" class="form-control rounded-0">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="message">Wiadomość</label>
<textarea name="message" id="message" name="message" cols="30" rows="7" class="form-control rounded-0" placeholder="Zostaw swoją wiadomość tutaj..."></textarea>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Wyślij!" class="btn btn-primary mr-2 mb-2">
</div>
</div>
</form>
Skrypt sendform3.php, który wywołuję przyciskiem wygląda następująco:
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "kontakt@domena.me";
$email_subject = "Kontakt ze strony ";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fname']) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fname = $_POST['fname']; // required
$lname = $_POST['lname']; // required
$email_from = $_POST['email']; // required
$subject = $_POST['subject']; // not required
$message = $_POST['message']; // 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 .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$lname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Zawartość formularza kontaktowego:\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Imię: ".clean_string($fname)."\n";
$email_message .= "Nazwisko: ".clean_string($lname)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Temat: ".clean_string($subject)."\n";
$email_message .= "Wiadomość: ".clean_string($message)."\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 -->
Dziękuję za kontakt. Skontaktuje się z Tobą w możliwie najkrótszym czasie
<?php
}
?>
Po naciśnięciu przycisku pojawia się biała strona, która w pasku adresu ma:
/sendform.php?fname=Jakiesimie&lname=&email=jakis%40email.com&subject=jakistemat&message=trescwiadomosci
Sama stronka jest w domenie ".me" (czarnogóra)
Hosting to: thecamels.org
Na hostingu mam konta pocztowe - działające bo wysyłają i odbierają maile.
Być może samo konto pocztowe lub hosting wymagają konfiguracji, jednak w tej kwestii nawet nie wiem czego szukać...
Dodam tylko, że wiadomość nie trafia do spamu, ani do kosza. Nigdzie jej nie ma... próbowałem wysyłać na adresy @gmail, @outlook i nic.
Bardzo proszę o pomoc.
Pozdrawiam