Salta al contenuto
  • CATEGORIES
  • La Community Connect.gt
  • Presentati alla Community
  • News Ufficiali da Connect.gt
  • Internet News
  • A Scuola Di
  • Digital Marketing
  • Intelligenza Artificiale
  • SEO & GEO
  • Web Marketing e Content
  • Google Analytics e Web Analytics
  • Google Ads & Advertising
  • YouTube
  • TikTok, Instagram e altri Social
  • Google Adsense, Affiliazioni e Guadagno
  • E-Commerce
  • Coding e Sistemistica
  • Help Center: consigli per il tuo progetto
  • Hosting e Cloud
  • Coding
  • CMS & Piattaforme Self-Hosted
  • Annunci e Collaborazioni
  • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
  • Collaborazioni WEB e Lavoro: offro e cerco
  • Impresa, Fisco e Leggi
  • Consulenza Legale e Professioni Web
  • Consulenza Fiscale, Imprese, Startup e P.Iva
  • Gli Off Topic
  • PC, Smartphone e altri Hardware
  • Tutti i Software
  • GT Fetish Cafè
  • Discussioni
  • 0 Non letti 0
  • Recenti
  • Hashtag
  • Popolare
  • Utenti
  • Privacy
  • Termini e condizioni
  • © 2026 Search On Media Group S.r.l.
Collassa
Connect.gt
Il network Search On
Connect.gt WMF AI Festival Accademia Advanced SEO Tool AgentCy Social Media Strategies Search Tech
Registrati Accedi
Connect.gt
Stream Interest Categorie Hashtag
  1. La community italiana di SEO, marketing digitale e AI
  2. Categorie
  3. Coding e Sistemistica
  4. Coding
  5. Script formmail con allegati su altervista funziona altrove no

Script formmail con allegati su altervista funziona altrove no

Pianificato Fissato Bloccato Spostato Coding
1 Post 1 Autori 2.0k Visualizzazioni 1 Seguito
  • Da Vecchi a Nuovi
  • Da Nuovi a Vecchi
  • Più Voti
Rispondi
  • Risposta alla discussione
Effettua l'accesso per rispondere
Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
  • R
    R
    rott
    scritto su ultima modifica di
    User Newbie 0
    #1
    Script formmail con allegati su altervista funziona altrove no

    Ciao a tutti, ho un piccolo problema con uno script in php per mandare email con un allegato.
    Con il sito hostato su altervista la cosa funzionava, mi arrivavano gli allegati integri, mentre con il nuovo hosting mi arrivano allegati danneggiati, ovvero con una dimensione pari a 0kb....
    Non so se è un problema di codice perchè su un hosting funziona tutto bene sull'altro no.

    Sotto posto il codice, non pretendo che ve lo leggiate, più che altro mi basta un consiglio su cosa vedere di sistemare o fare

    function get_ext($key) { 
        $key=strtolower(substr(strrchr($key, "."), 1)); 
        // Cause there the same right? 
        $key=str_replace("jpeg","jpg",$key); 
        return $key; 
    } 
     
    function phattach($file,$name) { 
        global $boundary; 
         
        $fp=@fopen($file,"r"); 
        $str=@fread($fp, filesize($file)); 
        $str=@chunk_split(base64_encode($str)); 
        $message="--".$boundary."\n"; 
        $message.="Content-Type: application/octet-stream; name=\"".$name."\"\n"; 
        //$message.="Content-disposition: attachment\n"; Thanks goes to someone named Chris (I think, it was awhile ago) for his fix below! 
        $message.="Content-disposition: attachment; filename=\"".$name."\"\n"; 
        $message.="Content-Transfer-Encoding: base64\n"; 
        $message.="\n"; 
        $message.="$str\n"; 
        $message.="\n"; 
     
        return $message; 
    } 
     
    //Little bit of security from people forging headers. People are mean sometimes :( 
    function clean($key) { 
        $key=str_replace("\r", "", $key); 
        $key=str_replace("\n", "", $key); 
        $find=array( 
            "/bcc\:/i", 
            "/Content\-Type\:/i", 
            "/Mime\-Type\:/i", 
            "/cc\:/i", 
            "/to\:/i" 
        ); 
      $key=preg_replace($find,"",$key); 
      return $key; 
    } 
     
    // Safe for register_globals=on =) 
     
    $error=""; 
    $types=""; 
    $sent_mail=false; 
     
    // Do some loopy stuff for the valid file types so people can see what types are valid before they try and upload invalid ones. 
     
    $ext_count=count($allowtypes); 
    $i=0; 
     
    foreach($allowtypes AS $extension) { 
         
        //Gets rid of the last comma 
         
        If($i <= $ext_count-2) { 
            $types .="*.".$extension.", "; 
        } Else { 
            $types .="*.".$extension; 
        } 
        $i++; 
    } 
    unset($i,$ext_count); // why not 
     
     
    // If they post the form start the mailin'! 
     
    If($_POST['submit']==true) { 
        extract($_POST, EXTR_SKIP); 
     
            // Check the form for errors 
         
            If(trim($yourname)=="") { 
                $error.="Non hai inserito il tuo nome e cognome.<br />"; 
            } 
             
            If(trim($youremail)=="") { 
                $error.="Non hai inserito il tuo indirizzo email.<br />"; 
            } Elseif(!eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$",$youremail)) { 
                $error.="Invalid email address.<br />"; 
            } 
     
            If(trim($emailsubject)=="") { 
                $emailsubject=$defaultsubject; 
            } 
     
            If(trim($yourmessage)=="") { 
                $error.="Non hai inserito un messaggio.<br />"; 
            } 
             
            // Verify Attachment info 
             
            If($allowattach > 0) { 
                 
                //Loopish 
                 
                For($i=0; $i <= $allowattach-1; $i++) { 
                     
                    If($_FILES['attachment']['name'][$i]) { 
                         
                        $ext=get_ext($_FILES['attachment']['name'][$i]); 
                        $size=$_FILES['attachment']['size'][$i]; 
                        $max_bytes=$max_file_size*1024; 
                         
                        //Check if the file type uploaded is a valid file type. 
                         
                        If(!in_array($ext, $allowtypes)) { 
                             
                            $error.= "Estensione del file allegato non valida: ".$_FILES['attachment']['name'][$i].", puoi allegare solo files in ".$types." Grazie.<br />"; 
                             
                            //Check the size of each file 
                             
                        } Elseif($size > $max_bytes) { 
                            $error.= "Il tuo: ".$_FILES['attachment']['name'][$i]." Ã?Æ?Ã?¨ troppo grande. Puoi allegare files grandi al massimo ".$max_file_size."kb.<br />"; 
                        } 
                         
                    } // If Files 
                     
                } // For 
     
                //Tally the size of all the files uploaded, check if it's over the ammount. 
                 
                  $total_size=array_sum($_FILES['attachment']['size']); 
                   
                $max_file_total_bytes=$max_file_total*1024; 
                 
                If($total_size > $max_file_total_bytes) { 
                    $error.="Puoi allegare files grandi al massimo ".$max_file_total."kb<br />"; 
                } 
                 
            } // If Allowattach 
     
        If($error) { 
         
            $display_message=$error; 
     
        } Else { 
             
            If($use_subject_drop AND is_array($subjects) AND is_array($emails)) { 
                $subject_count=count($subjects); 
                $email_count=count($emails); 
                 
                If($subject_count==$email_count) { 
                     
                    $myemail=$emails[$emailsubject]; 
                    $emailsubject=$subjects[$emailsubject]; 
                     
                } 
                 
            } 
             
             
            $boundary=md5(uniqid(time())); 
             
            //Little bit of security from people forging headers. People are mean sometimes :( 
             
            $yourname=clean($yourname); 
            $yourmessage=clean($yourmessage); 
            $youremail=clean($youremail); 
             
            //Headers 
             
            $headers="From: ".$yourname." <".$youremail.">\n"; 
            $headers.="Reply-To: ".$yourname." <".$youremail.">\n"; 
            $headers.="MIME-Version: 1.0\n"; 
            $headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n"; 
            $headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n"; 
            $headers.="X-Mailer: PHP/".phpversion()."\n"; 
            $headers.="X-Priority: ".$priority."\n"; 
            $headers.="Return-Path: <".$youremail.">\n"; 
            $headers.="This is a multi-part message in MIME format.\n"; 
     
            //Message 
                 
            $message = "--".$boundary."\n"; 
            $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; 
            $message.="Content-Transfer-Encoding: quoted-printable\n"; 
            $message.="\n"; 
            $message.="$yourmessage"; 
            $message.="\n"; 
     
            //Lets attach to something! =) 
             
            If($allowattach > 0) { 
                 
                For($i=0; $i <= $allowattach-1; $i++) { 
                     
                    If($_FILES['attachment']['name'][$i]) { 
                         
                        $message.=phattach($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]); 
                         
                    } 
                     
                } //For 
                 
            } // If 
             
             
            // End the message 
             
            $message.="--".$boundary."--\n"; 
             
            // Send the completed message 
             
            If(!mail($myemail,$emailsubject,$message,$headers)) { 
                 
                Exit("Attenzione, è avvenuto un errore. \n"); 
                 
            } Else { 
             
                $sent_mail=true; 
                 
            } 
     
        } // Else 
     
    } // $_POST
    
    1 Risposta Ultima Risposta
    Miglior risposta 0
    0

    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
    Rispondi
    • Risposta alla discussione
    Effettua l'accesso per rispondere
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti


    • Accedi

    • Non hai un account? Registrati

    • Accedi o registrati per effettuare la ricerca.
    • Primo post
      Ultimo post
    Home Accedi Registrati
    Menu
    • CATEGORIES
    • La Community Connect.gt
    • Presentati alla Community
    • News Ufficiali da Connect.gt
    • Internet News
    • A Scuola Di
    • Digital Marketing
    • Intelligenza Artificiale
    • SEO & GEO
    • Web Marketing e Content
    • Google Analytics e Web Analytics
    • Google Ads & Advertising
    • YouTube
    • TikTok, Instagram e altri Social
    • Google Adsense, Affiliazioni e Guadagno
    • E-Commerce
    • Coding e Sistemistica
    • Help Center: consigli per il tuo progetto
    • Hosting e Cloud
    • Coding
    • CMS & Piattaforme Self-Hosted
    • Annunci e Collaborazioni
    • Annunci Vendita e Acquisto: Pubblicità, Domini, Link e altro
    • Collaborazioni WEB e Lavoro: offro e cerco
    • Impresa, Fisco e Leggi
    • Consulenza Legale e Professioni Web
    • Consulenza Fiscale, Imprese, Startup e P.Iva
    • Gli Off Topic
    • PC, Smartphone e altri Hardware
    • Tutti i Software
    • GT Fetish Cafè
    • Discussioni
    • Non letti 0
    • Recenti
    • Hashtag
    • Popolare
    • Utenti
    • Privacy
    • Termini e condizioni
    • © 2026 Search On Media Group S.r.l.