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

    Invio e-mail con allegato

    Salve a tutti...
    Ho bisogno del vostro aiuto...
    Siccome sto facendo un FORM con i campi e un allegato file, com'è il codice d'invio e-mail con allegato?
    Non è così? Però, quando ricevo, non si vede un file allegato, ma decifra una marea di codici...

    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>PREVENTIVO ON-LINE</title>
    <link rel="stylesheet" href="stile_flash.css">
    </head>

    <body>
    <?php

    $confirm = $_REQUEST['confirm'];

    if($confirm)

    {

    // Recupero il valore dei campi del form

    $destinatario = $_POST['destinatario'];
    $nome = $_POST['nome'];
    $cognome = $_POST['cognome'];
    $marca = $_POST['marca'];
    $cilindrata = $_POST['cilindrata'];
    $danno = $_POST['danno'];
    $to = "aaa@aaa.it";
    $subject = "Preventivo On-line";

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

    // 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";

    $message = "--{$mime_boundary}\n";
    $message .= "

    PREVENTIVO ON-LINE

    Il cliente $nome $cognome dell'e-mail $destinatario, ti ha scritto:

    MARCA E MODELLO VEICOLO = $marca

    CILINDRATA = $cilindrata

    DESCRIZIONE DEL DANNO = $danno

    ALLEGATO FOTO = $allegato";

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

    $message .= "--{$mime_boundary}--\n";
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/octet-stream ; charset=iso-8859-1\n";
    $headers .= " boundary=\"{$mime_boundary}\"";
    $headers .= "From: $nome $cognome < $email >\n";

    // Invio la mail

    if (mail($to, $subject, $message, $headers))

    {

    echo "<table width=\"90%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_bianco_sinistro\" align=\"center\" />
    <tr>
    <td bgcolor=\"FFFF99\"><table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_gr\" align=\"center\" />
    <tr>
    <td></td>
    </tr>
    <tr>
    <td colspan=\"2\" align=\"center\">

    Grazie per averci inviato la tua richiesta.

    Ti risponderemo al più presto possibile.

    Buona giornata!

    LA MADONNINA ROMA

    <img src=\"images/car2.gif\" border=\"0\" />

    </p></td>
    </tr>
    </table>";

    } else {

    echo "

    Errore!</p>";

    }

    } else {

    echo"<form name=\"preventivo\" method=\"post\" enctype=\"multipart/form-data\" action=\"{$_SERVER['PHP_SELF']}?confirm=1\">
    <input type=\"hidden\" name=\"destinatario\" value=\"aa@aaa.it\">
    <table width=\"90%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_bianco_sinistro\" align=\"center\" />
    <tr>
    <td bgcolor=\"FFFF99\"><table width=\"100%\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" class=\"testo_gr\" align=\"center\" />
    <tr>
    <td></td>
    </tr>
    <tr>
    <td colspan=\"2\" align=\"center\">PREVENTIVO ON-LINE

    <img src=\"images/car2.gif\" border=\"0\" /></td>
    </tr>
    <tr>
    <td colspan=\"2\">Con il suo lancio in rete, da quest’anno, ti offre anche il preventivo on-line! Inviandoci alcune foto del danno del tuo mezzo, cerchiamo di fornirti un preventivo il più corretto possibile, senza farti muovere di casa.</td>
    </tr>
    <tr>
    <td colspan=\"2\"><hr></td>
    </tr>
    <tr>
    <td>NOME</td>
    <td><input type=\"text\" name=\"nome\" /></td>
    </tr>
    <tr>
    <td>COGNOME</td>
    <td><input type=\"text\" name=\"cognome\" /></td>
    </tr>
    <tr>
    <td>E-MAIL</td>
    <td><input type=\"text\" name=\"mittente\" /></td>
    </tr>
    <tr>
    <td valign=\"top\">MARCA
    E MODELLO VEICOLO
    </td>
    <td><textarea cols=\"20\" rows=\"4\" name=\"marca\"></textarea></td>
    </tr>
    <tr>
    <td>CILINDRATA</td>
    <td><input type=\"text\" name=\"cilindrata\" /></td>
    </tr>
    <tr>
    <td valign=\"top\">DESCRIZIONE
    DEL DANNO
    </td>
    <td><textarea cols=\"20\" rows=\"4\" name=\"danno\"></textarea></td>
    </tr>
    <tr>
    <td>ALLEGA FOTO</td>
    <td><input type=\"file\" name=\"allegato\" /></td>
    </tr>
    <tr>
    <td colspan=\"2\"><hr></td>
    </tr>
    <tr>
    <td colspan=\"2\" align=\"center\" >Una volta inviati i dati richiesti, ti contatteremo nel più breve tempo possibile.</td>
    </tr>
    <tr>
    <td colspan=\"2\"><hr></td>
    </tr>
    <tr>
    <td align=\"center\"><input type=\"reset\" value=\"Reimposta\" /></td>
    <td align=\"center\"><input type=\"submit\" value=\"Invia\" /></td>
    </tr>
    <tr>
    <td colspan=\"2\"></td>
    </tr>
    </table></td>
    </tr>
    </table>
    </form>";

    }

    ?>

    </body>
    </html>

  2. #2
    Io ho fatto così:

    <FORM ENCTYPE=\"multipart/form-data\" NAME=\"form_messaggio\" METHOD=\"post\" ACTION=\"invia_messaggio.php\">
    ......

    <TEXTAREA NAME=\"msg\" ROWS=\"4\" COLS=\"40\" WRAP=\"physical\"></TEXTAREA>
    <INPUT TYPE=\"file\" NAME=\"allegato\">
    ........

    in invia_messaggio.php, poi:


    $messaggio = "--XX-1234DED00099A\n";
    $messaggio .= "Content-Type: text/plain; charset=iso-8859-1\n";
    $messaggio .= "Content-Transfer-Encoding: 7bit\n";
    $messaggio.= "$msg\n\r";

    $messaggio.="--XX-1234DED00099A\n";
    $messaggio.="Content-Type: $tipo_file; name=$allegato_name\n";
    $messaggio.="Content-Transfer-Encoding: base64\n";
    $messaggio.="Content-Description: Nuovo file\n";
    $messaggio.="Content-Disposition: attachment; filename=$allegato_name\n\n";

    $fp=@fopen($allegato_name, "r");

    if ($fp) $data = fread($fp, filesize($allegato_name));

    $curr = chunk_split(base64_encode($data));

    fclose($fp);

    $messaggio .= "$curr\n--XX-1234DED00099A--\n";

    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/mixed; boundary=XX-1234DED00099A\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    $headers .= "From: PROVA@libero.it\n";


    @mail("DESTINATARIO", "OGGETTO DELLA EMAIL", $messaggio, $headers);

    a me funziona!

  3. #3
    Originariamente inviato da gianf_tarantino
    Io ho fatto così:
    ...

    Ciao sto provando il tuo script, ma mi dà questo errore:

    codice:
    Warning: fclose(): supplied argument is not a valid stream resource in /home/www/wwww.miosito.it/test/form_ALLEGATO/invia_messaggio.php on line 30
    Che può essere?

    tnx
    1,2,3,4,5,10,100 passi!

  4. #4
    $fp=@fopen($allegato_name, "r");

    Prova a togliere la @ qui, perché penso che anche qui dia un errore. Per dare quell'errore in chiusura del file, vuol dire che non lo ha aperto bene. Evidentemente non prende nulla in $allegato_name.
    Fai una verifica.

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