Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2005
    Messaggi
    2

    La funzione mail() errore allegato

    Ciao ho seguito la spiegaione sulla funzione mail() del sito e quando sono arrivato all'allegato parte che mi interessa ( voglio farmi inviare delle foto) l'ho provato in rete il problema e' il seguente mi invia l'allegato ma non me fa vedere la foto praticamente e byte inviati sono uguali a zero
    qualcuno puo aiutarmi? posto il codice

    <form action="sendmail.php" enctype="multipart/form-data" method="POST">
    <table cellpadding="0" cellspacing="0">
    <tr>
    <td>Destinatario: </td>
    <td><input type="text" name="Destinatario" size="40"></td>
    </tr>
    <tr>
    <td>Soggetto:</td>
    <td><input type="text" name="Soggetto" size="40"></td>
    </tr>
    <tr>
    <td>Allegato:</td><td><input type="file" name="allegato" size="40"></td>
    </tr>
    <tr>
    <td valign="top">Contenuto:</td>
    <td><textarea name="Contenuto" rows="15" cols="50"></textarea></td>
    </tr>
    <tr>
    <td height="30" valign="bottom" colspan="2" align="center"><input type="submit" value="Invia la mail">
    </tr>
    </table>
    </form>

    ora il sedmail.php

    <?php

    // RENDIAMO LO SCRIPT COMPATIBILE CON LE VERSIONI DI PHP < 4.1.0
    if(!isset($_POST)) $_POST = $HTTP_POST_VARS;
    if(!isset($_FILES)) $_FILES = $HTTP_POST_FILES;

    // RIPULIAMO I VARI CAMPI DEL MODULO
    $Destinatario = trim($_POST["Destinatario"]);
    $Soggetto = trim(stripslashes($_POST["Soggetto"]));
    $Contenuto = trim(stripslashes($_POST["Contenuto"]));

    // ASSEGNIAMO A VARIABILI PIU' LEGGIBILI, LE PROPRIETA' DELL'ALLEGATO
    $attach = $_FILES["allegato"]["tmp_name"];
    $file_name = $_FILES["allegato"]["name"];
    $file_type = $_FILES["allegato"]["type"];
    $file_size = $_FILES["allegato"]["size"];

    // DELIMITATORE
    $boundary = md5(uniqid(microtime()));

    // APRIAMO L'ALLEGATO PER LEGGERLO E CODIFICARLO
    $file = @fopen($attach, "r");
    $contents = @fread($file, $file_size);
    $encoded_attach = chunk_split(base64_encode($contents));
    @fclose($file);

    // INTESTAZIONI DELLA MAIL
    $mail_headers .= "MIME-version: 1.0\n";
    $mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
    $mail_headers .= "X-attachments: $file_name\n";

    // COSTRUIAMO IL CORPO DELLA MAIL
    $mail_body = "--$boundary\n";
    $mail_body .= "Content-Type: text/plain; charset=us-ascii\n";
    $mail_body .= "Content-Transfer-Encoding: 7bit\n\n";
    $mail_body .= "$Contenuto\n\n";
    $mail_body .= "--$boundary\n";
    $mail_body .= "Content-type: $file_type; name=\"$file_name\"\n";
    $mail_body .= "Content-Transfer-Encoding: base64\n";
    $mail_body .= "$encoded_attach\n";
    $mail_body .= "--$boundary--\n";

    // INVIO DELLA MAIL
    if(@mail($Destinatario, $Soggetto, $mail_body, $mail_headers)) { // SE L'INVIO E' ANDATO A BUON FINE...

    echo "La mail è stata inoltrata con successo.";

    } else {// ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";

    }

    ?>

    grazie

  2. #2
    Utente bannato
    Registrato dal
    Sep 2005
    Messaggi
    905
    $mail_headers .= "MIME-version: 1.0\n";
    $mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
    $mail_headers .= "X-attachments: $file_name\n";
    credo che sia il punto al primo $mail_headers (di sicuro però non so) prova a fare
    codice:
    $mail_headers = "MIME-version: 1.0\n"; 
    $mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\""; 
    $mail_headers .= "X-attachments: $file_name\n";

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2005
    Messaggi
    2

    ancora nulla

    ho provato a fare la modifica che mi hai detto ma nulla da fare l'allegato arriva ma no ne' visualizzabile perche di zero byte
    tra l'altro ho cambiato anche il file invece di una foto ho inviato un file txt.... qualcuno puo aiutarmi?

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.