Eccomi di nuovo qui....

intanto tanti auguri per il Natale da poco passato e per il 2015 che sta per arrivare!
Nuovo dilemma con lo script:
stavolta devo aggiungere un campo "select" per far scegliere all'utente tra 2 opzioni, solo che non so come far controllare quel campo... inoltre (non so se dipende da un'errata configurazione da parte mia), ogni volta che faccio un test online per l'invio della mail dal modulo, mi viene indicato "Risposta antispam errata" anche se questa è giusta!
Il codice è il seguente:
Codice: Seleziona tutto
session_start();
header('Content-type: text/html; charset=ISO-8859-1');
function captcha() {
$numb1 = rand(1, 9);
$numb2 = rand(1, 9);
$sommanumeri = $numb1 + $numb2;
$moltipnumeri = $numb1 * $numb2;
$operazioni = array(
1 => $sommanumeri,
2 => $moltipnumeri
);
$rand = rand(1, 2);
$_SESSION['antispam'] = $operazioni[$rand];
$str1 = $numb2;
$str2 = $numb1;
$rand_strings = array_rand(array_flip(array($str1, $str2)), 1);
if ($rand == 1) {
return $str1 . ' + ' . $str2;
} else {
return $str1 . ' x ' . $str2;
}
}
$risultato = NULL;
$errore_captcha = NULL;
if (isset($_POST['submit'])) {
$mittente = (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? stripslashes(trim($_POST['mittente'])) : trim($_POST['mittente']);
switch ($_POST['reparto']) {
case 'generico':
$email_destinatario = 'info@xxxxxxxxxxxxxxxx.com';
break;
//case 'commerciale':
// $email_destinatario = 'commerciale@sito.tld';
//break;
//case 'tecnico':
// $email_destinatario = 'tecnico@sito.tld';
//break;
}
if ( !preg_match('/^[.a-zA-Z0-9\-\'\s]{1,40}$/', $mittente) || !preg_match('/^[.a-z0-9_-]+@[.a-z0-9_-]+\.[a-z]{2,4}$/', $_POST['email_mittente']) || !preg_match('/^[0-9]{6,10}$/', $_POST['telefono']) || empty($_POST['messaggio']) ) {
$risultato = '<div id="error" style="color: #FF0000;"><span class="testonorm">Riempire tutti i campi in maniera corretta!</span></div>';
}
else {
if ($_POST['spamcode'] != @$_SESSION['antispam']) {
$errore_captcha = '<div id="error" style="color: #FF0000;"><span class="testonorm">Risposta antispam errata!</span></div>';
}
else {
$messaggio = (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? stripslashes(strip_tags($_POST['messaggio'])) : strip_tags($_POST['messaggio']);
$phpversion = (!@phpversion()) ? "N/A" : phpversion();
$header = "From: " . $mittente . " <" . $_POST['email_mittente'] . ">\n";
$header.= "Reply-To: " . $_POST['email_mittente'] . "\n";
$header.= "Return-Path: " . $_POST['email_mittente'] . "\n";
$header.= "X-Mailer: PHP " . $phpversion . "\n";
$header.= "MIME-Version: 1.0\n";
$header.= "Content-type: text/plain; charset=ISO-8859-1\n";
$header.= "Content-Transfer-encoding: 7bit\n";
if (@mail($email_destinatario, "Mail da form sito internet", "\nDa: " . $mittente . " (" . $_POST['email_mittente'] . " - IP: " . $_SERVER['REMOTE_ADDR'] . ")\n\nTelefono: " . $_POST['telefono'] . "\n\nTesto messaggio: \n$messaggio", $header)) {
$risultato = '<div id="success" style="color:;"><span class="testonorm"><strong>Email inviata, risponderemo il prima possibile.</strong></span></div>';
header('refresh: 4; url=' . $_SERVER['PHP_SELF']);
}
else {
$risultato = '<div id="error" style="color: #3C6;"><span class="testonorm">Si è verificato un errore: riprova più tardi</span></div>';
header('refresh: 4; url=' . $_SERVER['PHP_SELF']);
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contatti</title>
<link href="../style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url();
}
</style>
<link href="../stili.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main" align="center">
<form method="post" name="modulo" action="email.php" id="modulo">
<table width="760" border="0" cellpadding="5" cellspacing="5" bgcolor="#ebeff7" class="sfondo1">
<tr>
<td align="left"><strong class="testonormale">Nome / Name</strong></td>
<td align="left">
<input name="mittente" type="text" class="testonormale" size="34" maxlength="40" value="<?php echo (isset($_POST['mittente'])) ? htmlentities($_POST['mittente'], ENT_QUOTES) : NULL; ?>" /></td>
</tr>
<tr>
<td align="left"><strong class="testonormale">Email</strong></td>
<td align="left"><input name="email_mittente" type="text" class="testonormale" size="34" maxlength="40" value="<?php echo (isset($_POST['email_mittente'])) ? htmlentities($_POST['email_mittente'], ENT_QUOTES) : NULL; ?>" /></td>
</tr>
<tr>
<td align="left"><strong class="testonormale">Telefono / Phone</strong></td>
<td align="left"><input name="telefono" type="text" class="testonormale" size="34" maxlength="40" value="<?php echo (isset($_POST['telefono'])) ? htmlentities($_POST['telefono'], ENT_QUOTES) : NULL; ?>" /></td>
</tr>
<tr>
<td align="left" class="testonormale"><strong>Transfer</strong></td>
<td align="left"><select name="Transfer" class="testonormale">
<option value="shuttle" selected="selected">Shuttle</option>
<option value="private">Private</option>
</select></td>
</tr>
<tr>
<td align="left"><strong class="testonormale">Invia a / Send to</strong></td>
<td align="left"><select name="reparto" class="testonormale">
<option value="generico" selected="selected">Info
</option>
</select>
</td>
</tr>
<tr>
<td align="left" valign="top"><strong class="testonormale">Messaggio / Message</strong></td>
<td align="left"><textarea name="messaggio" cols="42" rows="4" class="testonormale"><?php echo (isset($_POST['messaggio'])) ? htmlentities($_POST['messaggio'], ENT_QUOTES) : NULL; ?></textarea><br /><?php echo $risultato . ' ' . $errore_captcha; ?> <br />
<span class="testonormalerosso">Quanto fa</span> <?php echo captcha(); ?> <input name="spamcode" type="text" size="2" maxlength="2" /> <input name="submit" type="submit" class="testodisclaimer" id="submit" style="font-weight: bold;" value="Invia modulo" />
Se potessi darmi qualche indicazione al riguardo te ne sarei veramente grato...
