title: PHPmailer sending email with Attachment
body: <p>I have a script for sending emails with PHPmailer (the class is different because I use a CRUD but the functions are the same)</p>
  
  <p>This is the script:</p>
  
  <pre><code>    if (array_key_exists('recipient', $_POST)) {
          $attachment = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['attachment']['name']));
          move_uploaded_file($_FILES['attachment']['tmp_name'], $attachment);
          $recipient = $_POST['recipient']; 
          $subject = $_POST['subject'];
          $content = $_POST['content'];
          //$attachment = $_POST['attachment'];
  
          $email-&gt;Sender = "noreply@fw.net";
          $email-&gt;Recipient = "noreply@fw.net";
          if (!empty($_POST['recipient'])) {
              $email-&gt;Recipient = $recipient;
          } else { 
              foreach ($bcc as $bcc) {
                  $email-&gt;addBcc($bcc);
          }
      }   
      //$email-&gt;addRecipient = $bcc;
      $email-&gt;Subject = $subject;
      $email-&gt;Content = $content; 
      $email-&gt;addAttachment($attachment, 'MyFile');
      $email-&gt;Format = "html";
      //$email-&gt;send();
  
      if(!$email-&gt;send()) {
          $msg = '&lt;div style="Color:red"&gt;Sent:&lt;/div&gt;'. $email-&gt;SendErrDescription;    
      } else {
          $msg = '&lt;div style="Color:green"&gt;not Sent&lt;/div&gt;';
          header("Refresh:5");
      }
  }
  </code></pre>
  
  <p>this the form: email.php (work on the same page script / form)</p>
  
  <pre><code>&lt;form id="mess" action="email.php" method="POST" enctype="multipart/form-data"&gt;
  &lt;?php if ($Page-&gt;CheckToken) { ?&gt;
  &lt;input type="hidden" name="&lt;?php echo TOKEN_NAME ?&gt;" value="&lt;?php echo $Page-&gt;Token ?&gt;"&gt;
  &lt;?php } ?&gt;
  &lt;div id="jsInfo" data-count="&lt;?php echo $count; ?&gt;"&gt;&lt;/div&gt;
  &lt;div class="card card-primary card-outline"&gt;
  .......
                   &lt;div class="form-group"&gt;
                    &lt;div class="btn btn-default btn-file"&gt;
                      &lt;i class="fa fa-paperclip"&gt;&lt;/i&gt; Allegato
                      &lt;input type="hidden" name="MAX_FILE_SIZE" value="100000"&gt; &lt;input type="file" name="attachment" id="attachment"&gt;
                    &lt;/div&gt;
                    &lt;p class="help-block"&gt;Max. 10MB&lt;/p&gt;
                  &lt;/div&gt;
  ........
                    &lt;button type="submit" value="Upload" name="submit" class="btn btn-primary"&gt;&lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt; Send &lt;/button&gt;
  </code></pre>
  
  <p>I changed the destination to php.ini I use wamp in local for testing
  from:</p>
  
  <pre><code>sys_temp_dir = "/tmp"
  </code></pre>
  
  <p>to</p>
  
  <pre><code>sys_temp_dir = "c:/Users/lt/Documents/Temp"
  </code></pre>
  
  <p>Question:</p>
  
  <p>Why is not attached to the original file(pdf,jpg,bmp,txt ecc..), but the *.tmp file is attached. ? where am I wrong?</p>
  
  <p>let's say I solved that. </p>
  
  <pre><code>don't works
  $attachment = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['attachment']['name']));
  move_uploaded_file($_FILES['attachment']['tmp_name'], $attachment);
  
  works
  $uploaddir = 'C:/wamp64/www/fw3/';
  $attachment_tmp = $_FILES['attachment']['tmp_name'];
  $attachment_name = $_FILES['attachment']['name'];
  move_uploaded_file($attachment_tmp, $uploaddir . $attachment_name);
  </code></pre>
  
  <p>I have two problems again ...
  1) How to send the attachment to all recipients?
  2) When sending a 4Mb file the page loads a lot of time, how can I modify the script to make the sending work in the background?</p>