Senin, 18 Juni 2018

PHP
Kirim attachment banyak / Multiple file dengan php
9 October 2009 00:00
Setelah membuat script Untuk kirim Attachment dengan 1 file, lalu bagaimana jika kita akan

mengirim email dengan banyak/ Multiple file.
Berikut script yang dibuat hanya ada beberapa yang perlu di ubah :

 

<?
$adminEmail = "$_POST[adminEmail]";
              
if($_POST['submit']) {
                    
    $to = $_POST['to'];
    $subject = $_POST['subject'];                          
                    
    $pengantar=$_POST[pengantar];
                                        
    $pengantarok =

"Dear&nbsp;&nbsp;".ucfirst(strtolower($_POST['Salutation']))."".ucfirst(strtolower($_POST['Suren

ame'])).",<br><br>";
    $pengantarok2 = "$pengantar<br><br>";
    $pesan = "<table width=700 border=0 cellpadding=0 cellspacing=0 align=center>
        <tr><td height='10'></td></tr>
        <tr><td>$pengantarok</td></tr><tr><td>$pengantarok2</td></tr><tr><td>
    <table width=700 border=0 cellspacing=0 cellpadding=0>
    <tr>
      <td height=25></td>
    </tr>
    </table>
    </td></tr></table>";    
                    
    $attach      = $_FILES['file1']['tmp_name'];
      $attach_type = $_FILES['file1']['type'];
      $attach_name = $_FILES['file1']['name'];

    $countattach = count($attach);
    
      $headers = "From: $adminEmail";


    // Generate string untuk batas (boundary)
    $semi_rand     = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
          
    // Tambahkan header untuk file yang akan dikirim
    $headers .= " MIME-Version: 1.0 " .
          "Content-Type: multipart/mixed; " .
          " boundary="{$mime_boundary}"";
        
    // Tambahkan pesan
    $message .= "--{$mime_boundary} " .
             "Content-Type: text/html; charset="iso-8859-1" " .
             "Content-Transfer-Encoding: 7bit " .
             $pesan . " ";
    $message .= "--{$mime_boundary} ";
                    
    for($i=0;$i<count($attach);$i++){

     // Apabila ada file yang di attach    
    if (is_uploaded_file($attach[$i])) {    
        // Baca file yang akan di attach/kirim ('rb' = read binary)
    $file = fopen($attach[$i],'rb');
    $data = fread($file,filesize($attach[$i]));
    fclose($file);
                    
    // Untuk transisi data gunakan base64_encode();
    $data = chunk_split(base64_encode($data));
                
    // Tambahkan pesan pada file yang dikirim.
    $message .= "Content-Type: {$attach_type[$i]}; " . " name="$attach_name[$i]" " .
        
    "Content-Transfer-Encoding: base64 " . $data . " ";
            
    $message .= "--{$mime_boundary} ";    
                    
    }        
            
    }
 
$body = "$message";
                    
mail($to, $subject, $body, $headers);
                  
echo '<b>Your mail had been send to '.$to.' recipients</b>';


} else {

?>                    
      <form name="letter" action="" method="post" enctype="multipart/form-data">
      <table width="100%"  border="0" cellspacing="0" cellpadding="5">
          <tr>
            <td width="23%">Salutation</td>
            <td width="77%"><font size="2" face="Verdana, Arial, Helvetica,

sans-serif"><input type="radio" name="Salutation" value="Mr.">Mr.&nbsp;<input type="radio"

name="Salutation" value="Mrs.">Mrs.</font></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr>
            <td width="23%">Name To</td>
            <td width="77%"><input name="Surename" type="text" id="Surename" size="35"

style="font-weight:bold" onFocus="this.value='';" value="isi sure name"></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr>
            <td width="23%">Email To</td>
            <td width="77%"><input name="to" type="text" id="to" size="35"

style="font-weight:bold" onFocus="this.value='';" value="isi to"></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr>
            <td>Subject</td>
            <td>
            <input name="subject" type="text" id="subject" size="60"

style="font-weight:bold" value=""></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr>
            <td>From Email</td>
            <td>
            <input name="adminEmail" type="text" id="adminEmail" size="60"

style="font-weight:bold" value=""></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr>
            <td>Pengantar Kata</td>
            <td><textarea name="pengantar" id="pengantar" rows="15" cols="80"

style="width:50%"></textarea></td>
          </tr>
          <tr><td colspan="2" height="10"></td></tr>
          <tr><td colspan="2" height="10"></td></tr>
        <? for($f=0;$f<20;$f++){ ?>
          <tr>
            <td>Attach File</td>
            <td><input type="file" name="file1[]"></td>
          </tr>
        <? } ?>
          <tr><td colspan="2" height="10"></td></tr>
              <tr>
                <td colspan="2"><input type="submit" name="submit" value="Send Mail"></td>
              </tr>
            </table>
          </form>
<? } ?>


Share |


AnciaNulky, wvhawHooneymboxy@crossmail.bid
18/06/2018 20:06:52
gsn casino slots online casinos for us players casino real money [url=https://onlinecasinoss.us.org/]online casino[/url]
AttfrNulky, nxbzhHooneymboxy@foremantlemail.bid
18/06/2018 20:06:45
slots for real money usa online casino casino play [url=https://onlinecasinoppl.com/]online casino games[/url]
ApgyqNulky, dxpqcHooneymboxy@daughertymail.bid
18/06/2018 20:06:38
bovada casino play casino casino online [url=https://onlinecasino-slots.us.org/]usa online casino[/url]
AjeafNulky, suqhcHooneymboxy@wednesburydirect.info
18/06/2018 20:06:37
bovada casino best online casino best online casinos [url=https://onlinecasinog24.com/]gsn casino slots[/url]
AabeqNulky, cclmuHooneymboxy@edwardsmail.bid
18/06/2018 20:06:35
tramadol opioid buy tramadol online ultram tramadol [url=https://tramadol50mg.com/]tramadol 50 mg[/url]
AghqtNulky, tbzttHooneymboxy@universityincanada.info
18/06/2018 20:06:35
usa online casino free online casino slots casino online [url=https://onlinecasinolo.com/]casino play[/url]
AopgkNulky, eqpxdHooneymboxy@oatwoodsmail.bid
18/06/2018 20:06:34
online casinos real money casino online casino gambling [url=https://onlinecasinovus.com/]gsn casino[/url]
AjpsdNulky, xfrboHooneymboxy@huhmail.bid
18/06/2018 20:06:23
casino slots casino real money best online casinos [url=https://onlinecasinogamesnt.us.org/]online casino[/url]
AuyzvNulky, xawbbHooneymboxy@simmonsmail.bid
18/06/2018 20:06:15
tramadol hcl 50mg tramadol hydrochloride tramadol hcl 50 mg tablet [url=https://buytramadol50mg.us.org/]buy tramadol[/url]
AivcuNulky, ltwntblestyEnetle@currymail.bid
18/06/2018 20:06:14
tramadol hcl 50 mg tablet tramadol 50 mg tablet buy painkillers online overnight | [url=https://buytramadol.us.org/]buy tramadol online[/url]
nmnJaInd, 3e4tgwe43r@gmail.com
18/06/2018 20:06:11
tadalafil buy cialis online generic tadalafil [url=http://cialisserfher.com/ ]cialis buy[/url]
AvremNulky, duhxrHooneymboxy@alpenstridemail.bid
18/06/2018 20:06:03
casino real money online casino online casinos for us players [url=https://onlinecasinomaniaa.com/]slots for real money[/url]
AsamlNulky, qiidzHooneymboxy@mercadomail.bid
18/06/2018 20:06:01
tramadol withdrawal tramadol generic tramadol 50mg [url=https://tramadol50mg.us.com/]tramadol 50 mg tablet[/url]
AkplwNulky, pbgnuHooneymboxy@noblemail.bid
18/06/2018 19:06:57
real money casino betfair online casino casino slots [url=https://onlinecasinoslots24.us.org/]online casino slots[/url]
geico auto insurance , outfitten@pochtar.top
18/06/2018 19:06:51
car insurance online car insurance car insurance [url=https://carinsurance18.us.com]progressive car insurance[/url]
AlpxpNulky, uxqiwHooneymboxy@slotshero.xyz
18/06/2018 19:06:50
jupiters casino star casino sydney cashman casino [url=https://au-onlinecasinogames.com/]casino[/url]
AuuhpNulky, ywnrwHooneymboxy@norgespinz.xyz
18/06/2018 19:06:49
tangiers casino login emu casino adelaide casino [url=https://australiaonlinecasinol24.com/]star casino[/url]
AnmdlNulky, rqetlHooneymboxy@downsmail.bid
18/06/2018 19:06:47
real money casino betfair online casino gsn casino slots [url=https://casino-online2018.us.org/]casino games[/url]
AxibxNulky, wnijeHooneymboxy@hoffmanmail.bid
18/06/2018 19:06:46
tramadol withdrawal tramadol hcl 50 mg buy tramadol online [url=https://buytramadol100mg.us.org/]tramadol 50 mg[/url]
EeuhjNulky, wbxhtblestyEnetle@woodsmail.bid
18/06/2018 19:06:41
tramadol 100 mg tramadol 50 mg buy tramadol online | [url=https://buytramadol50mg.us.org/]tramadol 100mg[/url]

Add Your Comment
Name
Email Address
Website / URL
Message
Mak [600] Karakter
Verify code


copyright © 2004 - 2013 All Rights Reserved, Web Development