Guest noisex Posted April 13, 2005 Report Share Posted April 13, 2005 Mosh kads var palidzet izdomat, kaa atrisinat problemu ar vairaku failu attacha nosutishanu ar PHP mail(); f-ju...Ar 1u failu nerodas problemas, viss tiek nosutits, MIME type etc lietas ir OK, tipo ar 1u failu http://paste.php.lv/1842 ...tachu man vajaga ar n-tajiem :) tipo forma ir: <input type="file" name="pfile[]" class="ffield"> <input type="file" name="pfile[]" class="ffield"> .... <input type="file" name="pfile[]" class="ffield"> var but cik velas :) f-ja, kas to apstaraa: function mail_attach_sender($to, $from, $subject, $message, $files ,$lb="\n") { $mime_boundary = "<<<:" . md5(uniqid(mt_rand(), 1)); $header = "From: ".$from; if(is_array($pfile)) { $header.= $lb; $header.= "MIME-Version: 1.0".$lb; $header.= "Content-Type: multipart/mixed;".$lb; $header.= " boundary=\"".$mime_boundary."\"".$lb; $content = "This is a multi-part message in MIME format.".$lb.$lb; $content.= "--".$mime_boundary.$lb; $content.= "Content-Type: text/plain; charset=\"windows-1257\"".$lb; $content.= "Content-Transfer-Encoding: 7bit".$lb.$lb; } $content.= $message.$lb; if(is_array($pfile)) { $content.= "--".$mime_boundary.$lb; foreach($files as $filename=>$filelocation) { if(is_readable($filelocation)) { $data = chunk_split(base64_encode(implode("", file($filelocation)))); $content.= "Content-Disposition: attachment;".$lb; $content.= "Content-Type: Application/Octet-Stream;"; $content.= " name=\"".$filename."\"".$lb; $content.= "Content-Transfer-Encoding: base64".$lb.$lb; $content.= $data.$lb; $content.= "--".$mime_boundary.$lb; } } } if(mail($to, $subject, $content, $header)) { return TRUE; } return FALSE; } Nu vot fishka tada, ka nevaru dabut tagad tiem n-tjaiem failiem isti filename un MIME type prieksh boundary :) bet njus sutas visi faili, kaa 0.dat, 1.dat etc :) Link to comment Share on other sites More sharing options...
bubu Posted April 13, 2005 Report Share Posted April 13, 2005 Kā tu izsauc mail_attach_sender() fju? Link to comment Share on other sites More sharing options...
Guest noisex Posted April 13, 2005 Report Share Posted April 13, 2005 njus taa ari izsauc: mail_attach_sender($to, $from, $subject, $message, $files ,$lb="\n"); bikku nokljudijos ar variabli, korochit files=pfile :) Link to comment Share on other sites More sharing options...
bubu Posted April 13, 2005 Report Share Posted April 13, 2005 Tad tu nepareizi izsauc. Izsaukumā parametrs nedrīkst būt izskatā ..., $lb="\n"); Parādi konkrētu rindiņu ar mainīgo veidiem, kurus tam padod. Link to comment Share on other sites More sharing options...
Guest noisex Posted April 13, 2005 Report Share Posted April 13, 2005 Njus problema jau nav taja ka visapr nestradaa, viss straaa visi atachi atnak, tikai vinjiem visiem nosaukums ir 0.dat, 1.dat, 2.dat etc, nu cik daudz lauku, tik daudz to failu ar .dat. ar 1u failu ir easy nolasit vinja filename, type, etc, ar vairakiem man neizdodas - tur ir ta problema, vienk esmu iestredzis -nav ideju vairs :) bet nu ok, varu izlabot to vietu. Link to comment Share on other sites More sharing options...
рпр Posted April 14, 2005 Report Share Posted April 14, 2005 Tad tu nepareizi izsauc. Izsaukumā parametrs nedrīkst būt izskatā ..., $lb="\n");Parādi konkrētu rindiņu ar mainīgo veidiem, kurus tam padod. 16316[/snapback] vareet jau var to dariit, tikai tas reaali funkcijai pados veertibbu true Link to comment Share on other sites More sharing options...
bubu Posted April 14, 2005 Report Share Posted April 14, 2005 vareet jau var to dariit, tikai tas reaali funkcijai pados veertibbu true 16322[/snapback] Vai tad? Manuprāt gan "\n", jo lietota jau piešķiršana (=) nevis salīdzināšana (==).Bet mans nolūks iepriekš bija pateikt, ka tas izsaukums kā viņš parādīja, neko taču neizsaka kādi mainīgie tiek padoti. Link to comment Share on other sites More sharing options...
Guest noisex Posted April 14, 2005 Report Share Posted April 14, 2005 Vai tad? Manuprāt gan "\n", jo lietota jau piešķiršana (=) nevis salīdzināšana (==).Bet mans nolūks iepriekš bija pateikt, ka tas izsaukums kā viņš parādīja, neko taču neizsaka kādi mainīgie tiek padoti. 16331[/snapback] tu gribi lai paradu kadas values es padodu uz to f-ju ? Link to comment Share on other sites More sharing options...
Delfins Posted April 14, 2005 Report Share Posted April 14, 2005 (edited) chunk_split(base64_encode(implode("", file($filelocation)))); nomainam uz chunk_split(base64_encode(file_get_contents($filelocation))); $content.= "Content-Type: Application/Octet-Stream;"; $content.= " name=\"".$filename."\"".$lb; nomainam uz $content.= "Content-Type: ".$files[$idx]['type']."; name=\"".$files[$idx]['name']."\"".$lb; Edited April 14, 2005 by Delfins Link to comment Share on other sites More sharing options...
Delfins Posted April 14, 2005 Report Share Posted April 14, 2005 tikai jāpiemin, ka $files masīvu jāpartaisa, ka tas būtu līdzīgs $_FILES foreach( $files AS $idx => $file ) { $files[$idx] = Array(); $files[$idx]['type'] = mime_content_type($file); $files[$idx]['name'] = $file; } Link to comment Share on other sites More sharing options...
Guest noisex Posted April 14, 2005 Report Share Posted April 14, 2005 Nu tagad final relize, pateicoties Delfinam :) <!--///////////////////// HTML INPUTS ////////////////////////--> <input type="file" name="pfile[]" class="ffield"> <input type="file" name="pfile[]" class="ffield"> <input type="file" name="pfile[]" class="ffield"> <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="<? echo ($max_file_size * 1024) ?>"> <? ######## SEND EMAIL WITH MULTIPLE ATTACHMENTS ######### $from = $name."<".$mail_.">"; $to = $email; $message = $body; $files = $_FILES['pfile']; mail_attach($to, $from, $subject, $message, $files, $lb="\n"); function mail_attach($to, $from, $subject, $message, $files ,$lb="\n") { $mime_boundary = "-----" . md5(uniqid(mt_rand(), 1)); $header = "From: ".$from; if(!empty($files)) { $header.= $lb; $header.= "MIME-Version: 1.0".$lb; $header.= "Content-Type: multipart/mixed;".$lb; $header.= ' boundary="'.$mime_boundary.'"'.$lb; $content = "This is a multi-part message in MIME format.".$lb; $content.= "--".$mime_boundary.$lb; $content.= "Content-Type: text/plain; charset=windows-1257; format=flowed".$lb; $content.= "Content-Transfer-Encoding: 7bit".$lb.$lb; } $content.= $message.$lb; if(!empty($files)) { foreach( $files['tmp_name'] AS $idx => $tmp_name ) { if(is_readable($files['tmp_name'][$idx])) { $content.= "--".$mime_boundary.$lb; $data = chunk_split(base64_encode(file_get_contents($files['tmp_name'][$idx]))); $content.= "Content-Disposition: attachment;".$lb; $content.= "Content-Type: ".$files['type'][$idx]."; name=\"".$files['name'][$idx]."\"".$lb; $content.= "Content-Transfer-Encoding: base64".$lb.$lb; $content.= $data.$lb; } } $content.= "--".$mime_boundary.'--'.$lb; } return mail($to, $subject, $content, $header ); } ?> Link to comment Share on other sites More sharing options...
Venom Posted April 15, 2005 Report Share Posted April 15, 2005 NB: neesi mēģinājis sūtīt Bcc/Cc headerus ar vairākiem lietotājiem? man nenosūta (mēģināju sadalīt gan ar ',', ', ', gan ",\n" u.c.) kā tur īsti pēc specifikācijas un kas beigu beigās apstrāda tos headerus - serveris vai maileris? Link to comment Share on other sites More sharing options...
Delfins Posted April 15, 2005 Report Share Posted April 15, 2005 NB: neesi mēģinājis sūtīt Bcc/Cc headerus ar vairākiem lietotājiem? man nenosūta(mēģināju sadalīt gan ar ',', ', ', gan ",\n" u.c.) kā tur īsti pēc specifikācijas un kas beigu beigās apstrāda tos headerus - serveris vai maileris? 16419[/snapback] SMTP apstrādā. Mailers tikai saliek headerus un caur soketiem nosuuta to SMTP serverim :) To: mails@aaa.lv, (\n) ... CC: [tas pats] vajadzētu iet... gļukains SMTP tev ? Link to comment Share on other sites More sharing options...
Recommended Posts