Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12
  1. #1
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605

    forma mail con allegato

    ho seguito questa guida:

    http://php.html.it/articoli/leggi/85...nzione-mail/1/

    ma se creo un pagina html e una pagina php come descritto a pagina 4 ho un problema, la mai arriva a destinazione, ma invece di vedere una mail con testo e allegato vedo questo:

    --42bf0ee20e6f1383809a5f45429b8c68
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit

    Testo della mail

    --42bf0ee20e6f1383809a5f45429b8c68
    Content-type: image/png; name="Spunto per ico.png"
    Content-Transfer-Encoding: base64

    kE9oVFcUh7/7YhAksbSOVkKFu4qzSMIjUbAuLJkYJzEyHZ6j+YNUJm/uzDxz583rfW9GKy5EEDdC
    oosuihtbcSVdliyy6KIgpZSAYt2ooDupgiC4ERkXbybzQvTChe +ec+7vnN+B3nQxCLQloeZHxslm
    5Nz8gtz+gF766QMoumEwns+fACgGgWbLefcfAuDhcDEI9OGnXx 7smdv194sf1k4/W/55/9b6Taff
    zM0vgJBAqhLzASC1GPMUkDofBRGIM0DKrRZLIAJgyBScCRC3gJ 2VBC8muKRCF8Q94Ds3MBFYBWCq
    6VYiEK8A2y95PljfAIdKoVsD6xZY1+fmF2Q8ZjQDR/ZBzz/d2EII9+7C14PdWHov7J6F1bFu7K2D
    AMSe9bA8NgqA6MtA77NW6+0gbL8JH260Wu9/bbU+/AY9T+BP7TZMs70jIf6F2AcAqazylfFc6WQz
    Mm/qZU+rxEo/nY79xnqw6nTocxzvBIBDcHsKZnfAzFX45Tns/x12/QH5fih8i3WZzo3UhQhgoh78






    questa stringa incomprensibile è molo più lunga, chiaramente l'ho tagiata perchè sarebbe stato inutile postarla tutta.

  2. #2
    Utente di HTML.it L'avatar di mariox
    Registrato dal
    Nov 2006
    Messaggi
    837
    Ciao...prova a postare il codice relativo alla form e alla funzione che invia l'email.

  3. #3
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605
    html:

    <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>



    e la pagina 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 È ANDATO A BUON FINE...

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

    } else {// ALTRIMENTI...

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

    }

    ?>

  4. #4
    Utente di HTML.it L'avatar di mariox
    Registrato dal
    Nov 2006
    Messaggi
    837
    devo andare a lavoro quindi te ne invio un'altra:
    Codice PHP:
    <?php

    # -=-=-=- PHP FORM VARIABLES (add as many as you would like)

    $name $_POST["name"];
    $email $_POST["email"];
    $invoicetotal $_POST["invoicetotal"];

    # -=-=-=- MIME BOUNDARY

    $mime_boundary "----Your_Company_Name----".md5(time());

    # -=-=-=- MAIL HEADERS

    $to "$email";
    $subject "This text will display in the email's Subject Field";

    $headers "From: Our Company <company@ourcompany.com>\n";
    $headers .= "Reply-To: Our Company <company@ourcompany.com>\n";
    $headers .= "MIME-Version: 1.0\n";
    $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";

    # -=-=-=- TEXT EMAIL PART

    $message "--$mime_boundary\n";
    $message .= "Content-Type: text/plain; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";

    $message .= "$name:\n\n";
    $message .= "This email is to confirm that \"Our Company\" has received your order.\n";
    $message .= "Please send payment of $invoicetotal to our company address.\n\n";
    $message .= "Thank You.\n\n";

    # -=-=-=- HTML EMAIL PART
     
    $message .= "--$mime_boundary\n";
    $message .= "Content-Type: text/html; charset=UTF-8\n";
    $message .= "Content-Transfer-Encoding: 8bit\n\n";

    $message .= "<html>\n";
    $message .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:14px; color:#666666;\">\n";
    $message .= "$name:
    \n"
    ;
    $message .= "
    \n"
    ;
    $message .= "This email is to confirm that \"Our Company\" has received your order.
    \n"
    ;
    $message .= "Please send payment of $invoicetotal to our company address.
    \n\n"
    ;
    $message .= "
    \n"
    ;
    $message .= "Thank You.
    \n\n"
    ;
    $message .= "</body>\n";
    $message .= "</html>\n";

    # -=-=-=- FINAL BOUNDARY

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

    # -=-=-=- SEND MAIL

    $mail_sent = @mail$to$subject$message$headers );
    echo 
    $mail_sent "Mail sent" "Mail failed";

    ?>
    prova questa ciao

  5. #5
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605
    non mi invia nemmeno la mail

  6. #6
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605
    cosa devo modificare della pagina php sopra postata?

    ps, avrei bisogni anche di avere 2 tasti per allegare 2 file diversi

  7. #7
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605
    aiuto, sto diventando pazzo

    c'è qualche cosa che non va nella codifica forse?

  8. #8
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    154
    A me va benissimo

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    154
    Ah dimenticavo, per far in modo che il client interpreti i tag html devi modificare:
    codice:
    // COSTRUIAMO IL CORPO DELLA MAIL
    $mail_body = "--$boundary\n";
    $mail_body .= "Content-Type: text/plain; charset=us-ascii\n";
    con:
    codice:
    // COSTRUIAMO IL CORPO DELLA MAIL
    $mail_body = "--$boundary\n";
    $mail_body .= "Content-Type: text/html; charset=us-ascii\n";

  10. #10
    Utente bannato
    Registrato dal
    Jul 2006
    Messaggi
    605
    Ho provato a fare la modifica che hai suggerito, ma non cambia assolutamente nulla.

    invece dell'allegato mi arriva sempre il codice del file.
    Immagini allegate Immagini allegate
    • Tipo di file: gif 1.gif‎ (18.5 KB, 38 visualizzazioni)

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.