Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Contact form un aiuto per controllo campi e antispam!

    Ciao ragazzi, premetto che con il PHP non ho dimestichezza, quello che riesco a smanettare arriva da una conoscenza generale sulla programmazione (vb).

    Ora ho questo codice PHP:

    codice:
    <?php // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
     $to = "info@miosito.com";  
     
     // IL SOGGETTO DELLA MAIL 
     
     $subject = "Modulo proveniente dal sito";  
     
     // COSTRUZIONE DEL CORPO DEL MESSAGGIO 
     $body = "Contenuto del modulo:\n\n";  
     $body .= "Dati personali ;
    nome: " . trim(stripslashes($_POST["nome"])) . "\n"; 
     $body .= "cognome: " . trim(stripslashes($_POST["cognome"])) . "\n"; 
     $body .= "Città: " . trim(stripslashes($_POST["citta"])) . "\n"; 
     $body .= "Oggetto: " . trim(stripslashes($_POST["oggetto"])) . "\n"; 
     $body .= "testo: " . trim(stripslashes($_POST["testo"])) . "\n"; 
     $body .= "mail: " . trim(stripslashes($_POST["mail"])) . "\n";  
     
     // INTESTAZIONI SUPPLEMENTARI 
     $headers = "From: Modulo utenti<INDIRIZZO-COME-SOPRA>";  
     
     // INVIO DELLA MAIL 
     if(@mail($to, $subject, $body, $headers)) { 
    
     // SE L'INOLTRO E' ANDATO A BUON FINE...  
    
    echo "La mail è stata inoltrata con successo.";  } else {
    	// ALTRIMENTI...  
    	echo "Si sono verificati dei problemi nell'invio della mail.";  }  
    	
    	?>
    Con questa parte di html:

    codice:
    <form name="form1" method="post" action="mail.php"> <table width="95%" align="center" > <tr> <td colspan="2"><div align="center">CONTACT FORM</div></td> </tr> <tr> <td width="16%">Name</td> <td width="84%"><input type="text" name="nome"></td> </tr> <tr> <td>Surname</td> 
     <td><input type="text" name="cognome"></td> </tr> <tr> <td>City</td> <td><input type="text" name="citta"></td> </tr> <tr> <td>Your E-mail </td> <td><input type="text" name="mail"></td> </tr> <tr> <td>Subject</td> 
     <td><input type="text" name="oggetto"></td> </tr> <tr> <td>Type text</td> 
     <td><textarea name="testo" cols="40" rows="10"></textarea></td> </tr> <tr> <td colspan="2"></td> </tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="Submit" value="Submit"> </div></td> </tr> </table> </form>
    Volevo chiedervi, come poter integrare 2 cose:

    1) Controllo dei campi prima del'invio
    2) Implementare un sistema antispam

    Faccio questa domanda perchè come modulo mi sembra molto facile da usare (basta impostare un valore) e in rete non ho trovato nulla di altrettanto semplice. Grazie.

  2. #2
    Non interfacciandosi con un Database, diciamo che potresti limitarti al controllo che già fai.

    Per evitare spam, dovresti implementare un sistema di captcha. Fai una ricerchina su google.

    Una domanda, ma questa riga che sta a significare?



    Codice PHP:
     $headers "From: Modulo utenti<INDIRIZZO-COME-SOPRA>"



  3. #3
    Originariamente inviato da Samleo
    Non interfacciandosi con un Database, diciamo che potresti limitarti al controllo che già fai.

    Per evitare spam, dovresti implementare un sistema di captcha. Fai una ricerchina su google.

    Una domanda, ma questa riga che sta a significare?



    Codice PHP:
     $headers "From: Modulo utenti<INDIRIZZO-COME-SOPRA>"


    Questo script non è stato realizzato da me l'ho trovato in rete... l'ho solo "tradotto" in inglese, ora provo a vedere, il mio problema è come e dove implementare i due script...

    Ps. non sono riuscito a capire in questo caso dove e come inserire il controllo empty...

  4. #4
    <?php // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
    $to = "info@miosito.com";
    if($_POST["nome"]=='' && $_POST["cognome"]=='' && $_POST["citta"]=='' && $_POST["oggetto"]=='' && $_POST["testo"]=='' && $_POST["mail"]=='')
    {
    echo "Tutti i campi sono obbligatori";
    }
    else
    {
    // IL SOGGETTO DELLA MAIL

    $subject = "Modulo proveniente dal sito";

    // COSTRUZIONE DEL CORPO DEL MESSAGGIO
    $body = "Contenuto del modulo:\n\n";
    $body .= "Dati personali ;
    nome: " . trim(stripslashes($_POST["nome"])) . "\n";
    $body .= "cognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
    $body .= "Città: " . trim(stripslashes($_POST["citta"])) . "\n";
    $body .= "Oggetto: " . trim(stripslashes($_POST["oggetto"])) . "\n";
    $body .= "testo: " . trim(stripslashes($_POST["testo"])) . "\n";
    $body .= "mail: " . trim(stripslashes($_POST["mail"])) . "\n";

    // INTESTAZIONI SUPPLEMENTARI
    $headers = "From: Modulo utenti<INDIRIZZO-COME-SOPRA>";

    // INVIO DELLA MAIL
    if(@mail($to, $subject, $body, $headers)) {

    // SE L'INOLTRO E' ANDATO A BUON FINE...

    echo "La mail è stata inoltrata con successo."; } else {
    // ALTRIMENTI...
    echo "Si sono verificati dei problemi nell'invio della mail."; }
    }
    ?>

  5. #5
    io ho fatto così la prima parte fa il controllo se l'email è corretta del tipo nome@sito.ext e se i campi sono stati scritti tutti
    Codice PHP:
    function is_email($email_to_test)
        {
            
    $re  "^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])";
            
    $re .= "+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$";
            if (
    ereg($re$email_to_test))
            {
                return 
    TRUE;
            }
            else
            {
                return 
    FALSE;
            }
        }

    $error = array();
    $good = array();
    $name trim($_POST['name']);
    $email trim($_POST['email']);
    $subject $_POST['subject'];
    $comments $_POST['comments'];
    if(isset(
    $_POST['submit'])){
        if(
    $name == ""){
        
    $error[0] = "Name is Required";
        
        
        }
        if(
    $email == "" or (is_email("$email") != TRUE)){
            
    $error[1] = "Please Insert Valid Email";
            
        }
        if(
    $subject  == ""){
            
    $error[3] = "Please Insert a Subject";
            
            }
        if(
    $comments  == ""){
            
    $error[4] = "Please Leave a Comments";
        
    }
    if(!
    $error){
    $to "myemail@email.com";
    $headers "From: ".$name." <".$email.">\r\n";
    $headers .= "Reply-To: ".$email."\r\n";
    $headers .= "Return-Path: ".$email."\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if(
    mail($to$name$comments$headers)) {
        
    $good[0] = "Message Send";
    }else{
        
    $error[5] = "Error!! Please Resend ";
    }
    }
    }
    ?> 
    ora ad ogni input del form non compilato correttamente faccio uscire l'errore
    Codice PHP:
    <form action="contact.php" method="POST" id="form-box">
                        <fieldset>
                            <legend class="n1">Your contact information</legend>
                                <label>[b]Name:[/b]</label>(required)

                                    <input type="text" name="name" value=""  /><?php echo $error[0]; ?>
                    
                                    <label>[b]E-mail:[/b]</label>(required)

                                    <input type="text" name="email" value="" /><?php echo $error[1]; ?>

                                    <label>[b]Subject:[/b]</label>(required)

                                    <input type="text" name="subject" value="" /><?php echo $error[3]; ?>

                                    

                        </fieldset>
                        <fieldset>
                            <legend class="n1">Your message</legend>
                                <label>[b]Message:[/b]</label>(required)<?php echo $error[4]; ?>

                                    <textarea name="comments" rows="7" cols="50" ></textarea>
                                    

                                    <input class="button" name="submit" type="submit" value="Send" /><?php echo $error[5]; ?><?php echo $good[0]; ?>
                        </fieldset>
                    </form>
    spero di esserti stato di aiuto

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.