Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Mail con + allegati

  1. #1

    Mail con + allegati

    Salve io ho visto lo script indicato sul forum e mi funziona tutto ok però io volevo allegare almeno un paio di file all'email e + di 1 non me ne invia come mai? cioè la mail arriva tranquillamente ma arriva 1 solo allegato, se bisogno posterò il codice

  2. #2
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    devi fare attenzione ai vari boundary...posta il codice.
    think simple think ringo

  3. #3
    Codice PHP:
    if($allegato1_name!="") {
    $file_dir "allegati";
    move_uploaded_file ($allegato1"allegati/$allegato1_name") or die ("Impossibile uplodare il file sul server");
    $titolo1=$allegato1_name;
    $f1="/home/creativa/public_html/vladimiro/allegati/$allegato1_name";
    $filez1 fopen($f1"r"); 
    $contents1 fread($filez1filesize($f1)); 
    $encoded_attach1 chunk_split(base64_encode($contents1)); 
    fclose($filez1); 
    }

    if(
    $allegato2_name!="") {
    $file_dir "allegati";
    move_uploaded_file ($allegato2"allegati/$allegato2_name") or die ("Impossibile uplodare il file sul server");
    $titolo2=$allegato2_name;
    $f2="/home/creativa/public_html/vladimiro/allegati/$allegato2_name";
    $filez2 fopen($f2"r"); 
    $contents2 fread($filez2filesize($f2)); 
    $encoded_attach2 chunk_split(base64_encode($contents2)); 
    fclose($filez2); 
    }

    if(
    $allegato3_name!="") {
    $file_dir "allegati";
    move_uploaded_file ($allegato3"allegati/$allegato3_name") or die ("Impossibile uplodare il file sul server");
    $titolo3=$allegato3_name;
    $f3="/home/creativa/public_html/vladimiro/allegati/$allegato3_name";
    $filez3 fopen($f3"r"); 
    $contents3 fread($filez3filesize($f3)); 
    $encoded_attach3 chunk_split(base64_encode($contents3)); 
    fclose($filez3); 
    }

    $boundary md5(uniqid(microtime())); 

    $variad=array($_POST['valori']);
    foreach(
    $variad as $valu){ 
    foreach(
    $valu as $keyg){ 

    $searchf "SELECT * from agenzie where id='$keyg'";
    $queryf mysql_query($searchf);
    $dataf mysql_fetch_array($queryf);

    $intestazioni="From: $mittente<$email>\nX-Mailer: Sismail Web Email Interface\nMIME-version: 1.0\nContent-type: multipart/mixed;\n boundary=\"Message-Boundary\"\nContent-transfer-encoding: 7BIT\nX-attachments: $titolo1 $titolo2 $titolo3";
    $body_top "--Message-Boundary\n"
    $body_top .= "Content-type: text/html; charset=iso-8859-1\n"
    $body_top .= "Content-transfer-encoding: 8BIT\n"
    $body_top .= "Content-description: Mail message body\n\n"

    $to "$dataf[email]";
    $subject $oggetto;
    $message $body;

    $msg_body $body_top $message;

    if(
    $allegato1_name!="") {
    $msg_body .= "\n\n--Message-Boundary\n";
    $msg_body .= "Content-type: $allegato1_type; name=\"$titolo1\"\n";
    $msg_body .= "Content-Transfer-Encoding: BASE64\n";  
    $msg_body .= "Content-disposition: attachment; filename=\"$titolo1\"\n\n";
    $msg_body .= "$encoded_attach1\n";
    $msg_body .= "--Message-Boundary--\n";
    }

    if(
    $allegato2_name!="") {
    $msg_body .= "\n\n--Message-Boundary\n";
    $msg_body .= "Content-type: $allegato2_type; name=\"$titolo2\"\n";
    $msg_body .= "Content-Transfer-Encoding: BASE64\n";  
    $msg_body .= "Content-disposition: attachment; filename=\"$titolo2\"\n\n";
    $msg_body .= "$encoded_attach2\n";
    $msg_body .= "--Message-Boundary--\n";
    }

    if(
    $allegato3_name!="") {
    $msg_body .= "\n\n--Message-Boundary\n";
    $msg_body .= "Content-type: $allegato3_type; name=\"$titolo3\"\n";
    $msg_body .= "Content-Transfer-Encoding: BASE64\n";  
    $msg_body .= "Content-disposition: attachment; filename=\"$titolo3\"\n\n";
    $msg_body .= "$encoded_attach3\n";
    $msg_body .= "--Message-Boundary--\n";
    }

    mail("$to","$subject",$msg_body$intestazioni); 
    Fammi sapere cosa sbaglio e grazie

  4. #4
    Moderatore di Server Apache L'avatar di marketto
    Registrato dal
    Sep 2001
    Messaggi
    5,858
    purtroppo nn riesco a provare il tuo codice, che mi sembra corretto.

    ti consiglio comunque di provare ad usare phpmailer, un'ottima classe per l'invio di email.
    http://phpmailer.sourceforge.net/



    think simple think ringo

  5. #5
    $msg_body .= "--Message-Boundary--\n";
    se tolgo questo in fondo a ogni allegato funziona grazie comunque l'importante è che abbia risolto!

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.