Multiple File Uploads As Email Attachments
<p>I display files before it is sent via email as attachments. I use this script to display files</p>

<pre><code>$(function(){
    var ul = $('#po_award p#file_1');

    $('#po_award').fileupload({
        add: function (e, data) {
            var tpl = $('&lt;li class="dialog"&gt;&lt;a style="color: #777777"&gt;&lt;/a&gt;&lt;/li&gt;');

            tpl.find('a').text(data.files[0].name)
                .append('&lt;a href="javascript:void(0)"&gt;&lt;span style="color: red; float: right"&gt;Delete&lt;/span&gt;&lt;/a&gt;');

            data.context = tpl.prependTo(ul);
            tpl.find('span').click(function(){
                if(tpl.hasClass('dialog')){
                    jqXHR.abort();
                }
                tpl.fadeOut(function(){
                    tpl.remove()
                });
            });
            var jqXHR = data.submit();
        },
    });
});
</code></pre>

<p>And this script as index and call script above</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form action="upload.php" id="form" method="post" enctype="multipart/form-data"&gt;
        &lt;div class="fitem"&gt;
            &lt;label style="width: 400px"&gt;Upload Files :&lt;/label&gt;
        &lt;/div&gt;
        &lt;div class="fitem" style="float: left"&gt;
            &lt;input style="width: 65px; height: 75px; float: right" class="easyui-filebox" name="attachment[]" multiple="true" buttonText="Add Files"/&gt;
        &lt;/div&gt;
        &lt;div class="easyui-panel" style="width:440px;height:75px;padding:5px;margin-top:0px"&gt;
            &lt;p id="file_1" style="list-style-type: none; margin-top: 0px"&gt;&lt;/p&gt;
        &lt;/div&gt;&lt;br&gt;
    &lt;/form&gt;

    &lt;button type="submit" name="submit" form="form"&gt;Send&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>This is upload.php script</p>

<pre><code>&lt;?php
require 'mail/PHPMailerAutoload.php';
include "conn.php";

date_default_timezone_set("Asia/Jakarta");
$id = 1;
$to = 'receiver@email.com';
$subject = 'Test';

if(isset($_POST['submit'])){
$attachment_name = $_FILES['attachment']['name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment = $_FILES['attachment']['tmp_name'];

include 'smtp.php';

$mail-&gt;addAddress($to);
$mail-&gt;Subject = $subject;
$mail-&gt;msgHTML('Tes');

foreach($attachment_name as $key =&gt; $att){
    $nama_file = $attachment_name[$key];
    $tmp_file = $attachment[$key];

    $mail-&gt;addAttachment($tmp_file, $nama_file);
}

if (!$mail-&gt;send()) {
    echo '&lt;script&gt;alert("Failed"); &lt;/script&gt;';
} else {
    echo '&lt;script&gt;alert("Success"); &lt;/script&gt;';
}
}
?&gt;
</code></pre>

<p>My problem is, when script.js is included in index, the files can't appear in email attachments. But when script.js is deleted from index, the files can appear in email attachments.</p>

<p>Any solution for this?</p>