title: PHPMailer using AddStringAttachment with AddAttachment
body: <p>I have a form that generates a PDF from the user inputs, As well as a file upload option.</p>
  <p>So the user can upload a file or not and I use <code>AddAttachment</code> for this part, And <code>AddStringAttachment</code>for the generated PDF.</p>
  <p>Here is my code:</p>
  <pre><code>//PDF
  $pdf = $dompdf-&gt;output();    
  
  //Configuration
  $mail = new PHPMailer;
  $mail-&gt;IsSMTP();
  $mail-&gt;CharSet  = 'UTF-8';
  $mail-&gt;Host     = 'localhost';
  $mail-&gt;SMTPAuth = false;
  
  //Email details
  $mail-&gt;From     = 'email@email.com'; 
  $mail-&gt;FromName = 'My email'; 
  $mail-&gt;Subject  = 'You have a new email';
  $mail-&gt;Body     = 'Hi there, You have a new message.&lt;br&gt;';
  $mail-&gt;AltBody  = 'Hi there, You have a new message.';
  
  //Loop through recipients
  $recipients = ['email1@email.com', 'email2@email.com'];
  
  foreach ($recipients as $recipient) {
      $mail-&gt;addAddress($recipient);
      $mail-&gt;AddStringAttachment($pdf, 'name.pdf'); 
      if (!empty($_FILES['upload']['tmp_path'])) {
          $mail-&gt;AddAttachment($_FILES['upload']['tmp_path'], 'upload.pdf');    
      }
  
      if ( !$mail-&gt;Send() ) {
          echo 'Not sent';     
      } else {
          echo 'Sent';
      }
  
      // Clear all addresses and attachments for next loop
      $mail-&gt;clearAddresses();
      $mail-&gt;clearAttachments();
  }
  </code></pre>
  <p>The issue is that when I upload a file, I receive 2 emails:
  1- With the attachment and generated PDF (Which is expected)
  2- With only the generated pdf. But the content is messed and looks wrong.</p>
  <p>When I don't upload a file, I get only 1 email.</p>
  <p>I tried to send to 1 email only and it's the same.</p>