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

    Perchè questo contact form non invia l'email??

    allora io ho questo contact form:
    Codice PHP:
    <?php

    header
    ('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-type: application/json');

    $admin_email 'miamail@miamail.com'// Your Email
    $message_min_length 5// Min Message Length


    class Contact_Form{
        function 
    __construct($details$email_admin$message_min_length){
            
            
    $this->name stripslashes($details['name']);
            
    $this->email trim($details['email']);
            
    $this->subject 'Contact from Your Website'// Subject 
            
    $this->message stripslashes($details['message']);
        
            
    $this->email_admin $email_admin;
            
    $this->message_min_length $message_min_length;
            
            
    $this->response_status 1;
            
    $this->response_html '';
        }


        private function 
    validateEmail(){
            
    $regex '/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i';
        
            if(
    $this->email == '') { 
                return 
    false;
            } else {
                
    $string preg_replace($regex''$this->email);
            }
        
            return empty(
    $string) ? true false;
        }


        private function 
    validateFields(){
            
    // Check name
            
    if(!$this->name)
            {
                
    $this->response_html .= '

    Please enter your name</p>'
    ;
                
    $this->response_status 0;
            }

            
    // Check email
            
    if(!$this->email)
            {
                
    $this->response_html .= '

    Please enter an e-mail address</p>'
    ;
                
    $this->response_status 0;
            }
            
            
    // Check valid email
            
    if($this->email && !$this->validateEmail())
            {
                
    $this->response_html .= '

    Please enter a valid e-mail address</p>'
    ;
                
    $this->response_status 0;
            }
            
            
    // Check message length
            
    if(!$this->message || strlen($this->message) < $this->message_min_length)
            {
                
    $this->response_html .= '

    Please enter your message. It should have at least '
    .$this->message_min_length.' characters</p>';
                
    $this->response_status 0;
            }
        }


        private function 
    sendEmail(){
            
    $mail mail($this->email_admin$this->subject$this->message,
                 
    "From: ".$this->name." <".$this->email.">\r\n"
                
    ."Reply-To: ".$this->email."\r\n"
            
    ."X-Mailer: PHP/" phpversion());
        
            if(
    $mail)
            {
                
    $this->response_status 1;
                
    $this->response_html '

    Grazie per averci contattato!</p>'
    ;
            }
        }


        function 
    sendRequest(){
            
    $this->validateFields();
            if(
    $this->response_status)
            {
                
    $this->sendEmail();
            }

            
    $response = array();
            
    $response['status'] = $this->response_status;    
            
    $response['html'] = $this->response_html;
            
            echo 
    json_encode($response);
        }
    }


    $contact_form = new Contact_Form($_POST$admin_email$message_min_length);
    $contact_form->sendRequest();

    ?>
    alla fine esce " Grazie per averci contattato! " ma non arriva nessuna mail..
    qualcuno sa aiutarmi?

  2. #2
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Verifica prima che l'email non arrivi tra lo spam.

    Verso che indirizzo stai provando ad inviare le email? Uno tra Libero ed Hotmail?
    Lo script è su un server online oppure stai provando in locale?
    Nel secondo caso hai configurato correttamente il mail server?

  3. #3
    Uso un'indirizzo tiscali, non c'è nello spam e sto provando in locale.

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,445
    Originariamente inviato da Andrel Medo
    Uso un'indirizzo tiscali, non c'è nello spam e sto provando in locale.
    Ecco, allora devi rispondere all'ultima domanda: hai configurato correttamente il mail server che hai in locale?

    Di default non è impostato, quindi non invia niente.
    Se non sai come si fa, basta che cerchi su un motore di ricerca e di guide ne troverai tantissime.
    Fondamentalmente si tratta di inpostare nel file php.ini
    SMTP = ... l'SMTP del tuo provider di posta (gmail, hotmail, tiscali...)
    smtp_port = 25

    La configurazione corretta però dipende dal tuo provider di posta, se usa un altra porta, se richiede autorizzazione tramite password...

    Comunque se cerchi trovi tutto.

    Dopo aver fatto le modifiche al php.ini ricordati di riavviare Apache.

  5. #5
    Grazie mille! ora funziona tutto!

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 © 2024 vBulletin Solutions, Inc. All rights reserved.