Pagina 2 di 2 primaprima 1 2
Visualizzazione dei risultati da 11 a 20 su 20
  1. #11
    TI HO CAPITO,HO CERCATO ANKE IO MA LO HAI VISTO COME' IL MIO SCRIPT? DEVO CREARE UN NUOVO CICLO E SU QUESTO NN CI SONO DUBBI,MA NON POSSO COPIARE TUTTO IL CODICE KE TROVO SU INTERNET,IO GLI ALTRI CAMPI CE L'HO GIA',POTRESTI FARMI UN FAVORE,MI SCRIVI IL CODICE ESATTO KE DEVO SCRIVERE SUL NUOVO CICLO PER FAR ARRIVARE GLI ALLEGATI PER MAIL? GRAZIE...SCUSA MA HO I MINUTI CONTATI

  2. #12
    io copio il codice e faccio nuovo ciclo sullo script ma non funziona,l'allegato non mi arriva,evidentemente va in conflitto con le mie variabili...

    / Valorizzo le variabili relative all'allegato
    $allegato = $_FILES['allegato']['tmp_name'];
    $allegato_type = $_FILES['allegato']['type'];
    $allegato_name = $_FILES['allegato']['name'];

    // Creo 2 variabili che riempirò più avanti...
    $headers = "From: " . $mittente;
    $msg = "";

    // Verifico se il file è stato caricato correttamente via HTTP
    // In caso affermativo proseguo nel lavoro...
    if (is_uploaded_file($allegato))
    {
    // Apro e leggo il file allegato
    $file = fopen($allegato,'rb');
    $data = fread($file, filesize($allegato));
    fclose($file);

    // Adatto il file al formato MIME base64 usando base64_encode
    $data = chunk_split(base64_encode($data));

    // Genero il "separatore"
    // Serve per dividere, appunto, le varie parti del messaggio.
    // Nel nostro caso separerà la parte testuale dall'allegato
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

    // Aggiungo le intestazioni necessarie per l'allegato
    $headers .= "\nMIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed;\n";
    $headers .= " boundary=\"{$mime_boundary}\"";

    // Definisco il tipo di messaggio (MIME/multi-part)
    $msg .= "This is a multi-part message in MIME format.\n\n";

    // Metto il separatore
    $msg .= "--{$mime_boundary}\n";

    // Questa è la parte "testuale" del messaggio
    $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
    $msg .= "Content-Transfer-Encoding: 7bit\n\n";
    $msg .= $messaggio . "\n\n";

    // Metto il separatore
    $msg .= "--{$mime_boundary}\n";

    // Aggiungo l'allegato al messaggio
    $msg .= "Content-Disposition: attachment;\n";
    $msg .= " filename=\"{$allegato_name}\"\n";
    $msg .= "Content-Transfer-Encoding: base64\n\n";
    $msg .= $data . "\n\n";

    // chiudo con il separatore
    $msg .= "--{$mime_boundary}--\n";
    }
    else
    {
    $msg = $messaggio;
    }

    // Invio la mail
    if (mail($destinatario, $oggetto, $msg, $headers))
    {
    echo "

    Mail inviata con successo!</p>";
    }else{
    echo "

    Errore!</p>";
    }

  3. #13
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    ah bene allora la parcella la invio a te

    nome campo file = documento
    Codice PHP:
    <?php

    $receiverMail 
    'tuamail@mail.it';

    $subject 'CHECK LIST';

    $nome trim(stripslashes($_POST['nome']));
    $cognome trim(stripslashes($_POST['cognome']));
    $struttura trim(stripslashes($_POST['struttura']));
    $auditor trim(stripslashes($_POST['auditor']));
    $verifica trim(stripslashes($_POST['verifica']));
    $checklist trim(stripslashes($_POST['checklist']));

    $d1_3trim(stripslashes($_POST['d1_3']));
    $d1_2trim(stripslashes($_POST['d1_2']));
    $d1_1trim(stripslashes($_POST['d1_1']));
    $d1_0trim(stripslashes($_POST['d1_0']));
    $d1_natrim(stripslashes($_POST['d1_na']));

    $d2_3trim(stripslashes($_POST['d2_3']));
    $d2_2trim(stripslashes($_POST['d2_2']));
    $d2_1trim(stripslashes($_POST['d2_1']));
    $d2_0trim(stripslashes($_POST['d2_0']));
    $d2_natrim(stripslashes($_POST['d2_na']));

    $d3_3trim(stripslashes($_POST['d3_3']));
    $d3_2trim(stripslashes($_POST['d3_2']));
    $d3_1trim(stripslashes($_POST['d3_1']));
    $d3_0trim(stripslashes($_POST['d3_0']));
    $d3_natrim(stripslashes($_POST['d3_na']));

    $d4_3trim(stripslashes($_POST['d4_3']));
    $d4_2trim(stripslashes($_POST['d4_2']));
    $d4_1trim(stripslashes($_POST['d4_1']));
    $d4_0trim(stripslashes($_POST['d4_0']));
    $d4_natrim(stripslashes($_POST['d4_na']));

    $d5_3trim(stripslashes($_POST['d5_3']));
    $d5_2trim(stripslashes($_POST['d5_2']));
    $d5_1trim(stripslashes($_POST['d5_1']));
    $d5_0trim(stripslashes($_POST['d5_0']));
    $d5_na=trim(stripslashes($_POST['d5_na']));

    $email $_POST['mail'];

    $stringa1 "ATTENZIONE Tutti i campi sono obbligatori!";

    $stringa2 "l'indirizzo mail non è valido";

    $stringa3 "la checklist è stata inviata.grazie!";

    $msgformat "La persona $nome $cognome ha compilato la seguente cechklist:\n\nnome checklist: $checklist\nstruttura: $struttura \nauditor: $auditor \nverifica del:$verifica \nmail: $email\nrisposte $d1_3 $d1_2 $d1_1 $d1_0 $d1_na \n$d2_3 $d2_2 $d2_1 $d2_0 $d2_na \n$d3_3 $d3_2 $d3_1 $d3_0 $d3_na \n$d4_3 $d4_2 $d4_1 $d4_0...";

    $i=1;
    while(
    $i<=110){
        if(
    $_POST['note'.$i] != '')
            
    $msgformat .= "Note".$i.":".$_POST['note'.$i]."";
        
    $i++;
    }

    $allegato $_FILES['documento']['tmp_name'];
    $allegato_type $_FILES['documento']['type'];
    $allegato_name $_FILES['documento']['name'];

    $headers "From: ".$email;
    $msgformat_final "";

    // Verifico se il file è stato caricato correttamente via HTTP
    // In caso affermativo proseguo nel lavoro...
    if(is_uploaded_file($allegato)){
        
    $file fopen($allegato,'rb');
        
    $data fread($filefilesize($allegato));
        
    fclose($file);

    // Adatto il file al formato MIME base64 usando base64_encode
        
    $data chunk_split(base64_encode($data));

    // Genero il "separatore"
    // Serve per dividere, appunto, le varie parti del messaggio.
    // Nel nostro caso separerà la parte testuale dall'allegato
        
    $semi_rand md5(time());
        
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

    // Aggiungo le intestazioni necessarie per l'allegato
        
    $headers .= "\nMIME-Version: 1.0\n";
        
    $headers .= "Content-Type: multipart/mixed;\n";
        
    $headers .= " boundary=\"{$mime_boundary}\"";

    // Metto il separatore
        
    $msgformat_final .= "--{$mime_boundary}\n";

    // Questa è la parte "testuale" del messaggio
        
    $msgformat_final .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
        
    $msgformat_final .= "Content-Transfer-Encoding: 7bit\n\n";
        
    $msgformat_final .= $messaggio "\n\n";

    // Metto il separatore
        
    $msgformat_final .= "--{$mime_boundary}\n";

    // Aggiungo l'allegato al messaggio
        
    $msgformat_final .= "Content-Disposition: attachment;\n";
        
    $msgformat_final .= " filename=\"{$allegato_name}\"\n";
        
    $msgformat_final .= "Content-Transfer-Encoding: base64\n\n";
        
    $msgformat_final .= $data "\n\n";

    // chiudo con il separatore
        
    $msgformat_final .= "--{$mime_boundary}--\n";
    }else{
        
    $msgformat_final $msgformat;
    }

    if (( 
    $nome == "" ) || ( $cognome == "" ) || ( $email == "" )){
        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa1\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }elseif(
    preg_match("#([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})#"$email)){
        
    mail($receiverMail$subject$msgformat_final$headers);

        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa3\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }

    // OPZIONE2:
    // popup di messaggio inviato e ridirezionamento ad una pagina web
    // decommentare $redirect
    // commentare tutto se si usa OPZIONE1 (per commentare usare /* all'inizio e */ alla fine delle righe da commentare)
    /* echo "<script language=\"JavaScript\">\n";
    echo "window.location.href=(\"$redirect\");\n";
    echo "</script>";
    }
    */

    else{
        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa2\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }

    ?>
    eXvision

  4. #14
    ciao grazie,si tutto quadra,ma mi hai fatto cambiare anke il pezzo

    else if (preg_match("#([w-.]+)@((?:[w]+.)+)([a-zA-Z]{2,4})#", $email))
    { mail($receiverMail, $subject, $msgformat_final, $headers);

    e adesso mi dice indirizzo mail non valido,ho provato a rimettere come ce l'avevo io cioè
    else if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))

    la mail mi arriva ma mi arriva solo l'allegato e tutte le altre variabili no,nome cognome struttura ecc....mi arriva solo l'allegato..come faccio?

  5. #15
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    Originariamente inviato da eleinad85
    ciao grazie,si tutto quadra,ma mi hai fatto cambiare anke il pezzo

    else if (preg_match("#([w-.]+)@((?:[w]+.)+)([a-zA-Z]{2,4})#", $email))
    { mail($receiverMail, $subject, $msgformat_final, $headers);

    e adesso mi dice indirizzo mail non valido,ho provato a rimettere come ce l'avevo io cioè
    else if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email))

    la mail mi arriva ma mi arriva solo l'allegato e tutte le altre variabili no,nome cognome struttura ecc....mi arriva solo l'allegato..come faccio?
    allora eregi è deprecato quindi è sconsigliato il suo utilizzo...
    il suo sostituto è preg_match..

    l'errore è dovuto al fatto che il tag PHP del forum modifica certi valori del pattern..
    utilizza

    codice:
    elseif(preg_match("#([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})#", $email))
    e vedrai che funziona..

    per quanto riguarda il messaggio cerca la riga


    Codice PHP:
    $msgformat_final .= $messaggio "\n\n"
    e sostituiscila con
    Codice PHP:
    $msgformat_final .= $msgformat "\n\n"
    eXvision

  6. #16
    ok grazie mille,funziona tt ok...e nel caso volessi inserire un altri campi file per allegare piu file? utilizzo lo stesso identico codice,cambiando logicamente il valore(ke sarà documento2,documento3 ecc......giusto?

  7. #17
    Utente di HTML.it L'avatar di brodik
    Registrato dal
    Jan 2009
    Messaggi
    765
    esatto... aggiungi i campi file nel form e ripeti la procedura per gli allegati nella parte php--
    eXvision

  8. #18
    no qlksa non va...ci ho provato,in pratica ho ripetuto il codice identico,e nelle prime tre righe del codice ho messo documento2,ma mi arriva solo uno di allegato,appunto il documento2 invece il primo non mi arriva....ma devo cambiare altre variabili oltre a 'documento'?

  9. #19
    sei sparito? dai un ultimo suggerimento come posso fare devo cambiare altre variabili tipo headers?

  10. #20
    Utente di HTML.it L'avatar di elisa21
    Registrato dal
    May 2004
    residenza
    Lucca
    Messaggi
    246
    Originariamente inviato da brodik
    ah bene allora la parcella la invio a te

    nome campo file = documento
    Codice PHP:
    <?php

    $receiverMail 
    'tuamail@mail.it';

    $subject 'CHECK LIST';

    $nome trim(stripslashes($_POST['nome']));
    $cognome trim(stripslashes($_POST['cognome']));
    $struttura trim(stripslashes($_POST['struttura']));
    $auditor trim(stripslashes($_POST['auditor']));
    $verifica trim(stripslashes($_POST['verifica']));
    $checklist trim(stripslashes($_POST['checklist']));

    $d1_3trim(stripslashes($_POST['d1_3']));
    $d1_2trim(stripslashes($_POST['d1_2']));
    $d1_1trim(stripslashes($_POST['d1_1']));
    $d1_0trim(stripslashes($_POST['d1_0']));
    $d1_natrim(stripslashes($_POST['d1_na']));

    $d2_3trim(stripslashes($_POST['d2_3']));
    $d2_2trim(stripslashes($_POST['d2_2']));
    $d2_1trim(stripslashes($_POST['d2_1']));
    $d2_0trim(stripslashes($_POST['d2_0']));
    $d2_natrim(stripslashes($_POST['d2_na']));

    $d3_3trim(stripslashes($_POST['d3_3']));
    $d3_2trim(stripslashes($_POST['d3_2']));
    $d3_1trim(stripslashes($_POST['d3_1']));
    $d3_0trim(stripslashes($_POST['d3_0']));
    $d3_natrim(stripslashes($_POST['d3_na']));

    $d4_3trim(stripslashes($_POST['d4_3']));
    $d4_2trim(stripslashes($_POST['d4_2']));
    $d4_1trim(stripslashes($_POST['d4_1']));
    $d4_0trim(stripslashes($_POST['d4_0']));
    $d4_natrim(stripslashes($_POST['d4_na']));

    $d5_3trim(stripslashes($_POST['d5_3']));
    $d5_2trim(stripslashes($_POST['d5_2']));
    $d5_1trim(stripslashes($_POST['d5_1']));
    $d5_0trim(stripslashes($_POST['d5_0']));
    $d5_na=trim(stripslashes($_POST['d5_na']));

    $email $_POST['mail'];

    $stringa1 "ATTENZIONE Tutti i campi sono obbligatori!";

    $stringa2 "l'indirizzo mail non è valido";

    $stringa3 "la checklist è stata inviata.grazie!";

    $msgformat "La persona $nome $cognome ha compilato la seguente cechklist:\n\nnome checklist: $checklist\nstruttura: $struttura \nauditor: $auditor \nverifica del:$verifica \nmail: $email\nrisposte $d1_3 $d1_2 $d1_1 $d1_0 $d1_na \n$d2_3 $d2_2 $d2_1 $d2_0 $d2_na \n$d3_3 $d3_2 $d3_1 $d3_0 $d3_na \n$d4_3 $d4_2 $d4_1 $d4_0...";

    $i=1;
    while(
    $i<=110){
        if(
    $_POST['note'.$i] != '')
            
    $msgformat .= "Note".$i.":".$_POST['note'.$i]."";
        
    $i++;
    }

    $allegato $_FILES['documento']['tmp_name'];
    $allegato_type $_FILES['documento']['type'];
    $allegato_name $_FILES['documento']['name'];

    $headers "From: ".$email;
    $msgformat_final "";

    // Verifico se il file è stato caricato correttamente via HTTP
    // In caso affermativo proseguo nel lavoro...
    if(is_uploaded_file($allegato)){
        
    $file fopen($allegato,'rb');
        
    $data fread($filefilesize($allegato));
        
    fclose($file);

    // Adatto il file al formato MIME base64 usando base64_encode
        
    $data chunk_split(base64_encode($data));

    // Genero il "separatore"
    // Serve per dividere, appunto, le varie parti del messaggio.
    // Nel nostro caso separerà la parte testuale dall'allegato
        
    $semi_rand md5(time());
        
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";

    // Aggiungo le intestazioni necessarie per l'allegato
        
    $headers .= "\nMIME-Version: 1.0\n";
        
    $headers .= "Content-Type: multipart/mixed;\n";
        
    $headers .= " boundary=\"{$mime_boundary}\"";

    // Metto il separatore
        
    $msgformat_final .= "--{$mime_boundary}\n";

    // Questa è la parte "testuale" del messaggio
        
    $msgformat_final .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
        
    $msgformat_final .= "Content-Transfer-Encoding: 7bit\n\n";
        
    $msgformat_final .= $messaggio "\n\n";

    // Metto il separatore
        
    $msgformat_final .= "--{$mime_boundary}\n";

    // Aggiungo l'allegato al messaggio
        
    $msgformat_final .= "Content-Disposition: attachment;\n";
        
    $msgformat_final .= " filename=\"{$allegato_name}\"\n";
        
    $msgformat_final .= "Content-Transfer-Encoding: base64\n\n";
        
    $msgformat_final .= $data "\n\n";

    // chiudo con il separatore
        
    $msgformat_final .= "--{$mime_boundary}--\n";
    }else{
        
    $msgformat_final $msgformat;
    }

    if (( 
    $nome == "" ) || ( $cognome == "" ) || ( $email == "" )){
        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa1\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }elseif(
    preg_match("#([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})#"$email)){
        
    mail($receiverMail$subject$msgformat_final$headers);

        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa3\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }

    // OPZIONE2:
    // popup di messaggio inviato e ridirezionamento ad una pagina web
    // decommentare $redirect
    // commentare tutto se si usa OPZIONE1 (per commentare usare /* all'inizio e */ alla fine delle righe da commentare)
    /* echo "<script language=\"JavaScript\">\n";
    echo "window.location.href=(\"$redirect\");\n";
    echo "</script>";
    }
    */

    else{
        echo 
    "<script language=\"JavaScript\">\n";
        echo 
    "alert(\"$stringa2\");\n";
        echo 
    "java-script:history.go(-1);";
        echo 
    "</script>";
    }

    ?>

    mi riaggancio a questo post chiedendo un aiuto, ovvero ho utilizzato parte di questo codice per l'invio di una mail con dati recuperati da un form, l'unica cosa che non riesco a far funzionare è l'allegato, in poche parole non viene recapitato con la mail.

    Ho fatto un po' di debugging e ho notato che la stampa a video mi 'entra' nella condizione di non is_uploaded_file($allegato), mi sono persa qualche cosa da fare per l'upload del file da form?
    Vi ringrazio per l'aiuto,
    Elisa
    L'immaginazione è l'intelligenza che si diverte

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