sto per la prima volta barcamenandomi nella creazione di siti. Per ora (più o meno) tutto bene, però sto riscontrando un po' di problemi nel momento in cui devo creare la contact form del mio sito.
Il codice HTML è questo:
Codice: Seleziona tutto
<form method="post" action="index.php">
<div style="display:block;" align="left">
<div style="display:block-inline; float:left; width: 48%;">
<label style="display:block;">Name</label>
<input name="name" placeholder="Type Here" required>
<label style="display:block;">Email</label>
<input name="email" type="email" placeholder="Type Here">
<label style="display:block;">Subject</label>
<input name="subject" placeholder="Type Here"></input>
<label style="display:block;">Message</label>
<textarea name="message" placeholder="Type Here"></textarea>
<label style="display:block;">*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here">
<input class="button" id="submit" name="submit" type="submit" value="SEND">
</form>
Codice: Seleziona tutto
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From:miosito.com';
$to = 'miamail@miamail.com';
$subject = $_POST['subject'];
$human = $_POST['human'];
$body = "From: $name\nE-Mail: $email\nSubject: $subject\nMessage:\n$message";
function IsInjected($str) {
$injections = array('(\n+)','(\r+)','(\t+)','(%0A+)','(%0D+)','(%08+)','(%09+)');
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
if(IsInjected($email)) {
echo "Bad email value! It seems you're an injecter bot";
exit;
}
else {
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent. Thank you!</p>';
}
else {
echo '<p>Something went wrong, go back and try again.</p>';
}
}
else if ($_POST['submit'] && $human != '4') {
echo 'You answered the anti-spam question incorrectly!';
}
}
else {
echo '<p>You need to fill in all required fields.</p>';
}
}
}
?>
E' tutta la mattina che cerco su internet, ma vuoi la mia scarsa conoscenza dell'argomento, vuoi la fumosità delle risposte che leggo, l'unica cosa sicura è che ci sto diventando matto!!!
Grazie in anticipo per qualunque risposta utile alla causa