Ho un problema: ho inserito in un sito un form per inviare mail alla casella di posta del sito stesso. il problema è che queste mail non arrivano, mentre se imposto come indirizzo del destinatario un mittente diverso queste arrivano.
Codice PHP:
$query="SELECT * FROM staff WHERE id='$staff'";
$result = mysql_query($query, $db);
$row = mysql_fetch_array($result);
if ($staff=="") {$target_address = "info@dominio.it";}
else {$target_address = $row[contatto];
echo "Scrivi a ".$row[nome];} // CSS classes & styles
$class_txt = "text";
$class_inputbutton = "inputButton";
$class_inputline = "inputLine";
$class_inputfield = "inputField";
$style_inputline = "width:355px;";
$style_inputfield = "width:355px; ";
$email_subject = "richiesta informazioni dal sito";
// error messages
$err_name = "Inserisci un nome.";
$err_phone = "Inserisci un numero di telefono.";
$err_msg = "Fai una richiesta.";
$err_email = "inserisci un indirizzo email valido.";
// misc text
$msg_date = "Data";
$msg_company = "Società";
$msg_name = "Nome";
$msg_address = "Indirizzo";
$msg_city = "CAP/Citta'";
$msg_phone = "Tel.";
$msg_email = "Email";
$msg_answerby = "Ricevi la risposta via";
$txt_email = "Email";
$txt_phone = "Telefono";
$txt_post = "Posta";
$txt_send = "Invia";
$txt_mandatory = "<span class='$class_txt'> i campi con l'asterisco (*) sono obbligatori</span>";
$msg_request = "Richiesta";
$msg_indent = 11;
// messages
$txt_thankyou = "<div class='$class_txt'><h2>Grazie per averci contattato!</h2>La tua richiesta è stata inoltrata e sarai contattato al più presto.</div>";
$txt_error = "<div style='color: #cc3300' class='$class_txt'><h2>Errore:</h2>{errors}</div>";
// {errors} is replaced by the errors that occurred
function spaces($num, $fill=" "){
$foo="";
for ($i=0; $i<$num; $i++)
$foo.=$fill;
return $foo; }
function isValidEmail($addr){
if(eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$", $addr))
return true;
else
return false; }
// start form evaluation
$error="foo";
if ($_REQUEST['do']=="send"){
$error=false;
if ($_REQUEST['name']=="") $error.="» $err_name
";
if ($_REQUEST['fon']=="") $error.="» $err_phone
";
if ($_REQUEST['message']=="") $error.="» $err_msg
";
if (!isValidEmail($_REQUEST['email'])) $error.="» $err_email
";
if ($error===false){
$message="$msg_date:".spaces($msg_indent-strlen($msg_date)).date("d M Y, H:i", time());
if ($_REQUEST['firma'])
$message.="\n$msg_company:".spaces($msg_indent-strlen($msg_company)).$_REQUEST['firma'];
if ($_REQUEST['name'])
$message.="\n$msg_name:".spaces($msg_indent-strlen($msg_name)).$_REQUEST['name'];
if ($_REQUEST['adresse'])
$message.="\n$msg_address:".spaces($msg_indent-strlen($msg_address)).$_REQUEST['adresse'];
if ($_REQUEST['ort'])
$message.="\n$msg_city:".spaces($msg_indent-strlen($msg_city)).$_REQUEST['ort'];
if ($_REQUEST['fon'])
$message.="\n$msg_phone:".spaces($msg_indent-strlen($msg_phone)).$_REQUEST['fon'];
$message.="\n$msg_email:".spaces($msg_indent-strlen($msg_email))."mailto:".$_REQUEST['email'];
$message.="\n\n".spaces(strlen("$msg_answerby ".$_REQUEST['kontakt'])+1, "=");
$message.="\n$msg_answerby ".$_REQUEST['kontakt']."!\n";
$message.=spaces(strlen("$msg_answerby ".$_REQUEST['kontakt'])+1, "=");
if ($idannuncio != "")
{$message .= $_REQUEST['annuncio'];}
else {
$message.="\n\n$msg_request:\n\n".$_REQUEST['message'];}
mail($target_address, $email_subject, $message, "From: ".$_REQUEST['email']);
echo $txt_thankyou;
}else if ($error!==false) $error=str_replace("{errors}", $error, $txt_error);
}
if ($error!==false){
if($error!="foo") echo $error;
// form
echo "<script language='JavaScript' type='text/JavaScript'>\n";
echo "window.onload = function(){ document.form1.firma.focus(); }\n";
echo "</script>\n";
echo "<form name='form1' method='post' action=''>\n";
echo "<table border='0' cellpadding='1' cellspacing='0' class='txt'>\n";
echo "<tr><td></td>\n";
echo "<td height='19'></td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>$msg_company</td>\n";
echo "<td height='19'><input name='firma' id='firma' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['firma']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>*$msg_name</td>\n";
echo "<td height='19'><input name='name' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['name']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>$msg_address</td>\n";
echo "<td height='19'><input name='adresse' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['adresse']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>$msg_city</td>\n";
echo "<td height='19'><input name='ort' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['ort']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>*$msg_phone</td>\n";
echo "<td height='19'><input name='fon' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['fon']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>*$msg_email</td>\n";
echo "<td height='19'><input name='email' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['email']."' />\n";
echo "</td></tr>\n";
echo "<tr><td width='75' class='$class_txt'>*$msg_answerby</td>\n";
echo "<td height='19' class='$class_txt'><input name='kontakt' type='radio' value='$txt_email' checked=\"checked\" /> $txt_email\n";
echo "<input name='kontakt' type='radio' value='$txt_phone' /> $txt_phone\n";
echo "<input name='kontakt' type='radio' value='$txt_post' /> $txt_post\n";
echo "</td></tr>\n";
if ($idannuncio==""){
echo "<tr><td width='75' class='$class_txt'>*$msg_request</td>\n";
echo "<td height='19'><textarea name='message' cols='45' style='$style_inputfield' rows='10' class='$class_inputfield'>".$_REQUEST['message']."</textarea></td></tr>\n"; } else {
$db = mysql_connect(localhost, $username, $dbpassword);
if ($db == FALSE)
die ("Errore nella connessione. Verificare i parametri nel file config.inc.php");
mysql_select_db($database, $db)
or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
$query="SELECT * FROM annunci WHERE id='$id'";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result))
{$breve=$row[breve];}
echo "<tr><td width='75' class='$class_txt'> </td>\n";
echo "<td height='19'><textarea readonly='readonly' cols='45' name='message' type='text' id='annuncio' class='$class_inputfield'> Richiedi informazioni per annuncio Rif.".$_REQUEST['idannuncio']." (";
$query="SELECT * FROM annunci WHERE id='$idannuncio'";
$result = mysql_query($query, $db);
while ($row = mysql_fetch_array($result))
{echo $row[breve];
echo ") </textarea>\n";}
echo "</td></tr>\n";}
echo "<tr><td width='75' ></td>\n";
echo "<td height='19' align='right'>$txt_mandatory</td></tr>\n";
echo "<tr><td width='75'></td>\n";
echo "<td height='19'><input name='Submit' type='submit' class='$class_inputbutton' value='$txt_send' />\n";
echo "<input name='do' type='hidden' id='do' value='send' /></td>\n";
echo "</tr></table>\n";
echo "</form>\n"; }
/* ######################### END Contact Form ##########################
##################################################################### */ ?>