salve a tutti
avrei bisogno, in una form, di poter fare un controllo sul campo mail.
Ovviamente non chiedo di verificare che l'indirizzo sia realmente esistente ma quanto mano che l'utente che mi lascia la mail inserisca una stringa di testo contenente la "@".
La mia form è stata realizzata con HTML:
e di una pagina di risposta mail.php :codice:<script type="text/javascript" language="javascript"> function checkrequired(which){ var pass=true if (document.images){ for (i=0;i<which.length;i++){ var tempobj=which.elements[i] if (tempobj.name.substring(0,8)=="required"){ if (((tempobj.type=="text"||tempobj.type=="textarea")&&tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&tempobj.selectedIndex==-1)){ pass=false break } } } } if (!pass){ alert("I campi sono obbligatori. Clicca su OK e compila il modulo") return false } else return true } </script> <form onSubmit="return checkrequired(this)" action="mail.php" method="post"> <table width="30%" align="center" > <tr> <td width="30%" align="right" class="style4">Nome *</td> <td width="70%" align="right"> <div align="left"> <input type=text name="requirednome" size="30" /> </div></td></tr> <tr> <td width="30%" align="right" class="style4"> E-mail *</td> <td width="70%" align="right"><div align="left"> <input type=text name="requiredmail" size="30" /> </div></td></tr> <tr> <td colspan="2"><div align="center"> <input type="submit" name="submit" value="Iscrivimi"> </div></td> </tr> </table> </form>
Cosa posso aggiungere e dove per poter costringere l'utente ad usare almeno la @ nel campo relativo alla mail?codice:<?php // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL $to = "miamail@miosito.com"; // IL SOGGETTO DELLA MAIL $subject = "Iscrizione dal sito web"; // COSTRUZIONE DEL CORPO DEL MESSAGGIO $body = "Dati per Invio Newsletter:\n\n"; $body .= "nome: " . trim(stripslashes($_POST["requirednome"])) . "\n"; $body .= "mail: " . trim(stripslashes($_POST["requiredmail"])) . "\n"; // INTESTAZIONI SUPPLEMENTARI $headers = "From: Iscrizione <INDIRIZZO-COME-SOPRA>"; // INVIO DELLA MAIL if(@mail($to, $subject, $body, $headers)) { // SE L'INOLTRO E' ANDATO A BUON FINE... echo "L'iscrizione è avvenuta con successo."; } else {// ALTRIMENTI... echo "Si sono verificati dei problemi nell'invio della mail."; } ?>
Grazie anticipatamente!

Rispondi quotando