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

    invio mail con allegato file txt presente sul sito

    Grazie in anticipo a tutti...

    In una cartella del mio sito ho un file .txt che deve essere inviato come allegato alla mail di un utente.

    Ho fatto così, ma il messaggio arriva senza allegato... (posto parte del codice che interessa)

    <?

    $subject = "copia txt";
    $attach="d:/inetpub/webs/sitocom/file/cartella/copia.txt";
    $boundary = md5(uniqid(microtime()));
    $file_name = $_FILES[$attach]["name"];
    $file_type = $_FILES[$attach]["type"];
    $file_size = $_FILES[$attach]["size"];

    // APRO ALLEGATO PER 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";

    // CORPO DEL MESSAGGIO
    $messaggio = "--$boundary\n";
    $messaggio .= "Content-Type: text/plain; charset=us-ascii\n";
    $messaggio .= "Content-Transfer-Encoding: 7bit\n\n";
    $messaggio .= "testo messaggio";

    $messaggio .= "--$boundary\n";
    $messaggio .= "Content-type: $file_type; name=\"$file_name\"\n";
    $messaggio .= "Content-Transfer-Encoding: base64\n";
    $messaggio .= "$encoded_attach\n";
    $messaggio .= "--$boundary--\n";

    $to = 'dest@destinatario.com';
    $posta = 'no-reply@sito.com';

    ini_set('sendmail_from', $posta); // Invia email da @miodominio.com
    if(@mail($to, $subject, $messaggio, $mail_headers)) {
    echo "
    E' stata appena inviata una copia del file a $to";
    }
    else
    {
    echo "ERRORE..";
    }
    ?>

  2. #2
    nessuno sa aiutarmi?

  3. #3
    Originariamente inviato da danieledani
    nessuno sa aiutarmi?

    Qualche aiutino?

    Grazie

  4. #4
    ho apportato alcune modifiche, così ricevo l'allegato MA E' VUOTO...

    Aiutatemi per favore...
    grazie


    <?
    $subject = "Copia file";
    $attach = "d:/inetpub/webs/sitocom/file/file.txt";
    $posta = "no-reply@sito.com";

    // INTESTAZIONI DELLA MAIL
    $headers .= "MIME-version: 1.0\n";
    $headers .= "Content-type: multipart/mixed; boundary=\"XX-1234DED00099A\"\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    $headers .= "From: " .$posta;

    // Corpo del messaggio
    $messaggio = "--XX-1234DED00099A\n";
    $messaggio .= "Content-Type: text/plain; charset=iso-8859-1\n";
    $messaggio .= "Content-Transfer-Encoding: 7bit\n\r";
    $messaggio .= "\n Messaggio \n";
    $messaggio .= "--XX-1234DED00099A\n";
    $messaggio .= "Content-Type: application/octet-stream; name=\"$attach\"\n";
    $messaggio .= "Content-Transfer-Encoding: base64\n";
    $messaggio .="Content-Disposition: attachment\n\r";

    $fp=@fopen($attach, "r");
    if ($fp) { $data = fread($fp, filesize($attach)); }
    $allega = base64_encode($data);

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

    $sentOK = mail($to, $subject, $messaggio, $headers);
    if ($sentOK==1)
    {
    echo "invio OK, tutto regolare ";
    }
    else { echo "invio KO.."; }
    ?>

  5. #5
    C'è qualcuno????

  6. #6
    Originariamente inviato da danieledani
    ho apportato alcune modifiche, così ricevo l'allegato MA E' VUOTO...

    Aiutatemi per favore...
    grazie


    <?
    $subject = "Copia file";
    $attach = "d:/inetpub/webs/sitocom/file/file.txt";
    $posta = "no-reply@sito.com";
    $to = "destinatario@sito.com";

    // INTESTAZIONI DELLA MAIL
    $headers .= "MIME-version: 1.0\n";
    $headers .= "Content-type: multipart/mixed; boundary=\"XX-1234DED00099A\"\n";
    $headers .= "Content-Transfer-Encoding: 7bit\n";
    $headers .= "From: " .$posta;

    // Corpo del messaggio
    $messaggio = "--XX-1234DED00099A\n";
    $messaggio .= "Content-Type: text/plain; charset=iso-8859-1\n";
    $messaggio .= "Content-Transfer-Encoding: 7bit\n\r";
    $messaggio .= "\n Messaggio \n";
    $messaggio .= "--XX-1234DED00099A\n";
    $messaggio .= "Content-Type: application/octet-stream; name=\"$attach\"\n";
    $messaggio .= "Content-Transfer-Encoding: base64\n";
    $messaggio .="Content-Disposition: attachment\n\r";

    $fp=@fopen($attach, "r");
    if ($fp) { $data = fread($fp, filesize($attach)); }
    $allega = base64_encode($data);

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

    $sentOK = mail($to, $subject, $messaggio, $headers);
    if ($sentOK==1)
    {
    echo "invio OK, tutto regolare ";
    }
    else { echo "invio KO.."; }
    ?>
    Qualche suggerimento???

  7. #7
    non posso credere che nessuno sappia aiutarmi!

  8. #8
    Utente di HTML.it
    Registrato dal
    Mar 2006
    Messaggi
    33
    ciao, ho visto che l'ultimo post l'hai fatto a dicembre, se ancora ti può essere utile questo è il link dove trovi quello che ti serve...
    http://www.webcheatsheet.com/php/sen...php#attachment
    ciao...

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.