Form mail con validazione lo controllate please ?
-
Ciao a tutti potreste gentilmente controllarmi questi codici per l'invio di un form con validazione, non funziona premetto che è un form che ho prelevato da internet e modificato aggiungendo altri campi (Città,Cognome) in origine vi era solo :name,email,subject, e msg, premetto pure che non capisco una mazza di php ma credo che sia il linguaggio + semplice per realizzare un formmail, quello qui sotto è il codice relativo al file
invio.php<?php
$receiverMail = "[email protected]";$nome = ltrim(rtrim(strip_tags(stripslashes($_POST['nome']))));
$cognome = ltrim(rtrim(strip_tags(stripslashes($_POST['cognome']))));
$città = ltrim(rtrim(strip_tags(stripslashes($_POST['citta']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$oggetto = ltrim(rtrim(strip_tags(stripslashes($_POST['oggetto']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));$ip = getenv("REMOTE_ADDR");
$msgformat = "From: $nome ($ip)\nEmail: $email\n\n$msg";// VALIDATION
if(empty($nome) || empty($cognome) || empty($citta) || empty($email) || empty($oggetto) || empty($msg)) {
echo "<h3>L'email non è stata inviata</h3><p>Riempite tutti i campi richiesti Grazie</p>";
}
elseif(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
echo "<h3>The email was not sent</h3><p>The email address is invalid</p>";
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>The email has been sent!</h3><p>I will get back to you as soon as possible.</p>"; }
?>Questo, quello relativo al form
<form method="post" action="contatti.php">
<p>Nome:
<input name="nome" type="text" size="25" maxlength="40" />
Cognome:
<input name="cognome" type="text" size="25" maxlength="40" />
<br />
<br />
Città:
<input name="citta" type="text" id="citta" size="25" maxlength="40" />
Email:
<input name="email" type="text" size="25" maxlength="40" />
<br />
<br />
Oggetto:
<input name="oggetto" type="text" size="25" maxlength="40" />
</p>
<p> <br />
Messaggio:<br />
<textarea name="msg" cols="50" rows="6"></textarea>
<br />
<br />
<input type="reset" value="Cancella" />
<input type="submit" value="Invia" />
</p>
</form>Dove è l'errore ????
Grazie in anticipo !!!!!!
-
Definisci "non funziona"

Cosa ti aspetti faccia?

-
-
-
-
ciao
con questo codice
if(empty($nome) || empty($cognome) || empty($citta) || empty($email) || empty($oggetto) || empty($msg)) {
echo "<h3>L'email non è stata inviata</h3><p>Riempite tutti i campi richiesti Grazie</p>";
}verifichi che nessuno dei campi sia vuoto. se tutti i campi sono vuoti procede con l'analisi dell'indirizzo email ed infine con l'invio della mail stessa utilizzando però un messaggio che non comprende le informazioni aggiunte da te.
per aggiungere le informazioni devi fare:
$msg = $nome.' - '.$cognome. ' - '.$citta.' - '.$msg;e aggiungi questa riga prima di
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
-
Non funziona !!!!!

<?php
$receiverMail = "[email protected]";$nome = ltrim(rtrim(strip_tags(stripslashes($_POST['nome']))));
$cognome = ltrim(rtrim(strip_tags(stripslashes($_POST['cognome']))));
$città = ltrim(rtrim(strip_tags(stripslashes($_POST['citta']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$oggetto = ltrim(rtrim(strip_tags(stripslashes($_POST['oggetto']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));$ip = getenv("REMOTE_ADDR");
$msgformat = "From: $nome ($ip)\nEmail: $email\n\n$msg";// VALIDATION
if(empty($nome) || empty($cognome) || empty($citta) || empty($email) || empty($oggetto) || empty($msg)) {
echo "<h3>L'email non è stata inviata</h3><p>Riempite tutti i campi richiesti Grazie</p>";
}
elseif(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
echo "<h3>The email was not sent</h3><p>The email address is invalid</p>";
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>The email has been sent!</h3><p>I will get back to you as soon as possible.</p>"; }
?>Tymba ho aggiunto la stringa
$msg = $nome.' - '.$cognome. ' - '.$citta.' - '.$msg;
coma da te suggerita ma non è cambiato nulla.
A me non interessa questo form in particolare l'importante è che abbia i campi: Nome,Cognome,Città,Email,Oggetto e Messaggio
-
-
ehm.... credo la mia domanda sia banale, ma...
tu ci hai mandato il codice di invio.php, ma il form ha come action "contatti.php". non è forse quello?
e poi, un'altra curiosità... sei sicuro di aver settato correttamente il file php.ini per inviare le mail? lo dico solo perché io non sono mai riuscito!

-
Ripeto il formmail ha solo due file uno chiamato "contatti.php" e l'altro "invio.php"
contatti.php è questo
<form method="post" action="contatti.php">
<p>Nome:
<input name="nome" type="text" size="25" maxlength="40" />
Cognome:
<input name="cognome" type="text" size="25" maxlength="40" />
<br />
<br />
Città:
<input name="citta" type="text" id="citta" size="25" maxlength="40" />
Email:
<input name="email" type="text" size="25" maxlength="40" />
<br />
<br />
Oggetto:
<input name="oggetto" type="text" size="25" maxlength="40" />
</p>
<p> <br />
Messaggio:<br />
<textarea name="msg" cols="50" rows="6"></textarea>
<br />
<br />
<input type="reset" value="Cancella" />
<input type="submit" value="Invia" />
</p>
</form>invio.php è questo
<?php
$receiverMail = "[email protected]";$nome = ltrim(rtrim(strip_tags(stripslashes($_POST['nome']))));
$cognome = ltrim(rtrim(strip_tags(stripslashes($_POST['cognome']))));
$città = ltrim(rtrim(strip_tags(stripslashes($_POST['citta']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$oggetto = ltrim(rtrim(strip_tags(stripslashes($_POST['oggetto']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));$ip = getenv("REMOTE_ADDR");
$msgformat = "From: $nome ($ip)\nEmail: $email\n\n$msg";// VALIDATION
if(empty($nome) || empty($cognome) || empty($citta) || empty($email) || empty($oggetto) || empty($msg)) {
echo "<h3>L'email non è stata inviata</h3><p>Riempite tutti i campi richiesti Grazie</p>";
}
elseif(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $email)) {
echo "<h3>The email was not sent</h3><p>The email address is invalid</p>";
}
else {
mail($receiverMail, $subject, $msgformat, "From: $name <$email>");
echo "<h3>The email has been sent!</h3><p>I will get back to you as soon as possible.</p>"; }
?>Non esiste un file php.ini
-
metti come action nel form del file contatti.php "invio.php"!! altrimenti ti rimanda alla stessa pagina che contiene il form!
il file php.ini è quello che contiene vari settaggi del linguaggio... non è un file del tuo sito! devi verificare di aver inserito in quel file tutte le informazioni necessarie perché la funzione mail() possa funzionare.
-
-
figurati!

fosse stato un problema più complesso mica l'avrei saputo risolvere!

Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi
