Ciao a tutti. Premetto che sono sono un programmatore e che le mie competenze per quanto riguarda php sono minime, quindi ciò che faccio è cercare di recuperare degli script su internet e metterli insieme al meglio...
Sul sito che ho sviluppato per un mio cliente ho creato la classica pagina contatti con un contact form validato sia con jquery che con php. La validazione client-side funziona, ma, sebbene inserisca tutti i campi richiesti, non riesco a far mandare la mail perché si verifica qualche problema nella validazione php.
La pagina è visualizzabile all'indirizzo http://bakokkogroup.it/contatti.php

Ecco qui il codice della mia pagina ripulito delle parti non necessarie:

Codice PHP:
<?php
include_once ($_SERVER["DOCUMENT_ROOT"].'/inc/common.php');
?>
 
<?php
//If the form is submitted
if( isset($_POST['submit']) )
{
    
//  NAME (requested) field validation
    
if(trim($_POST['name']) == '') {
        
$hasError true;
    } else {
        
$name trim($_POST['name']);
    }

    
//  TELEPHONE (optional) field validation
    
if (!eregi("^[0-9]+$"trim($_POST['telephone']))) {
        
$hasError true;
    } else {
        
$subject trim($_POST['telephone']);
    }
    
    
//  FAX field validation optional
    
if (!eregi("^[0-9]+$"trim($_POST['fax']))) {
        
$hasError true;
    } else {
        
$subject trim($_POST['fax']);
    }
    
    
//  EMAIL (requested) field validation
    
if(trim($_POST['email']) == '')  {
        
$hasError true;
    } else if (!
eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$"trim($_POST['email']))) {
        
$hasError true;
    } else {
        
$email trim($_POST['email']);
    }
    
    
// ADDRESS (optional) field validation
    
if (!eregi("^[a-zA-Z0-9]+$"trim($_POST['address']))) {
        
$hasError true;
    } else {
        
$subject trim($_POST['address']);
    }

    
// CITY (optional) field validation
    
if (!eregi("^[a-zA-Z0-9]+$"trim($_POST['city']))) {
        
$hasError true;    
    } else {
        
$name trim($_POST['city']);
    }
    
    
//  Check to make sure MESSAGE (requested) were entered
    
if(trim($_POST['message']) == '') {
        
$hasError true;
    } else {
        if(
function_exists('stripslashes')) {
            
$messages stripslashes(trim($_POST['message']));
        } else {
            
$messages trim($_POST['message']);
        }
    }

    
//  If there is no error, send the email
    
if( !isset($hasError) ) {
        
$emailTo 'info@bakokkogroup.it'//destination email address here
        
$body "Nome e Cognome: $name \n\nTelefono: $telephone \n\nFax: $fax \n\nEmail: $email \n\nIndirizzo: $address \n\nCittà: $city \n\nMessaggio:\n $message";
        
$headers 'From: My Site <'.$emailTo.'>' "\r\n" 'Reply-To: ' $email;
        
mail($emailTo$subject$body$headers);
        
$emailSent true;
    }
}
?>


<!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" xml:lang="it" lang="it">
    <head>
        <title>Titolo</title>        
    </head>

    <body id="contatti" onload="initialize()">
    
        <h3>Contact form</h3>
        
        <?php if(isset($hasError)) { //If errors are found ?>
            <p class="form-error" style="color:red">Messaggio di errore</p>
        <?php ?>
    
        <?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
            <p class="form-success" style="color:green">Email inviata correttamente</p>
        <?php ?>
        
        <form id="contactform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
                
            <label class="inlined" for="name">Nome e Cognome</label>
            <input type="text" class="input-text validate[required,custom[onlyLetter],length[0,50]]" id="name" name="name"  value="<?php echo $_POST['name'?>" />
    
            <label class="inlined" for="telephone">Telefono (optional)</span></label>
            <input type="text" class="input-text validate[optional,custom[onlyNumber],length[0,20]]" id="telephone" name="telephone" value="<?php echo $_POST['telephone'?>"/>
    
            <label class="inlined" for="fax">Fax (opzionale)</span></label>
            <input type="text" class="input-text validate[optional,custom[onlyNumber],length[0,20]]" id="fax" name="fax" value="<?php echo $_POST['fax'?>"/>
                                                            
            <label class="inlined" for="email">Email</label>
            <input type="text" class="input-text validate[required,custom[email],length[0,50]]" id="email"  name="email" value="<?php echo $_POST['email'?>"/>
    
            <label class="inlined" for="address">Indirizzo (opzionale)</span></label>
            <input type="text" class="input-text validate[optional,length[0,100]]" id="address" name="address" value="<?php echo $_POST['address'?>" />
            
            <label class="inlined" for="city">Citta' (opzionale)</span></label>
            <input type="text" class="input-text validate[optional,custom[onlyLetter],length[0,50]]" id="city" name="city" value="<?php echo $_POST['city'?>" />
            
            <label class="textarea inlined" for="message">Messaggio</label>
            <textarea class="input-text validate[required,length[6,300]]" id="message" name="message" rows="6" cols="150"><?php echo $_POST['message'?></textarea>
    
            <input class="button" type="submit" value="invia" name="submit" />
            
        </form> 

    </body>
</html>
Qualcuno di voi riesce ad individuare il mio errore (o orrore)?
Grazie in anticipo

Mattia