Witam, jestem nowy, dopiero się uczę, więc proszę o wyrozumiałość.
Mam taki skrypt formularza kontaktowego:
<?php
if (empty($_POST['submit'])) { echo "<div id=\"fk\"><br /><form method=\"post\"><span style=\"color: #1777b1; font-weight: bold;\">Imię i nazwisko*</span><input type='text' name='in' style=\"width: 345px; height: 22px; border: 1px solid #d5d5d5; margin-bottom:10px\"><br /> Firma<input type='text' name='firma' style=\"width: 345px; height: 22px; border: 1px solid #d5d5d5; margin-bottom:10px\"><br />
Dane kontaktowe<input type='dane' name='dane' style=\"width: 345px; height: 74px; border: 1px solid #d5d5d5; margin-bottom:10px\"><br />
<span style=\"color: #1777b1; font-weight: bold;\">E-mail*</span><input type='text' name='email' style=\"width: 345px; height: 22px; border: 1px solid #d5d5d5; margin-bottom:10px\"><br />
Treść<input type='text' name='tresc' style=\"width: 345px; height: 125px; border: 1px solid #d5d5d5; margin-bottom:10px\"><br />
<input type=\"submit\" name=\"submit\" class=\"send\"; value=\"Wyślij\"><br /><br />
* pola oznaczone gwiazdką są wymagane
</div>";
}
elseif (!empty($_POST['in']) && !empty($_POST['email'])) { $header .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$header .= "Reply-To: $_POST[email]";
$message = "Treść wiadomosci:\n$_POST[tresc]\nWysłał: $_POST[in]\ne-mail: $_POST[email]\nDane kontaktowe: $_POST[dane]\nFirma: $_POST[firma]";
@mail("mojmail@domena.pl","formularz kontaktowy","$message","$header") or
die('Nie udało się wysłać wiadomości.'); echo "<div><strong><br />Wiadomość została wysłana.</strong></div>"; }
else echo "<span style=\"color: #FF0000; text-align: center;\"><br />Proszę wypełnić wymagane pola.</span>"; ?>
I taką funkcję walidacji:
function checkEmail($email) {
if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)){ list
($username,$domain)=split('@',$email); if(!getmxrr ($domain,$mxhosts)){
return false;
}
return true;
}
return false;
}
Którą wywołuje się:
$email = trim($_POST['email']); if(!checkEmail($email)) {
echo 'Invalid email address!'; }
else {
echo 'Email address is valid'; }
Moje pytanie - jak to połączyć, żeby sprawdzało wpisany do formularza mail? Próbowałem już chyba wszystkiego...