title: PHPmailer - Add pdf file as attachment doesn't work
body: <p><strong>My Goal:</strong></p>
  
  <p>Use <code>AddStringAttachment()</code> to send a auto-generated base64 string as a <code>.pdf</code> file to another email address.</p>
  
  <p><strong>Coding Environment:</strong></p>
  
  <p>I'm working on WordPress with a ajax call passing a base64 string to the server. The size of the string is usually around 30kbs, it can be guaranteed not exceeding over 50kbs. I have <code>MAX_EXECUTION_TIME</code> 120s.</p>
  
  <p><strong>What I've Been Working Through:</strong></p>
  
  <p>I succeeded:</p>
  
  <ul>
  <li>Sending plain text body</li>
  <li>Sending a small <code>.txt</code> file</li>
  </ul>
  
  <p>I failed:</p>
  
  <ul>
  <li>Sending base64 string using <code>AddStringAttachment()</code>. The server returns me a <a href="http://#" rel="nofollow noreferrer">504 Gateway Time-out</a> error most of time, even if <code>$mail-&gt;send()</code> function passes through, I can only receive a corrupt <code>.pdf</code> file with 10kbs bigger than original size.</li>
  <li>Sending a already exist <code>.pdf</code> file with <code>AddAttachment()</code>, The server also returns me a <a href="http://#" rel="nofollow noreferrer">504 Gateway Time-out</a> error, and I also get a warning like <a href="http://#" rel="nofollow noreferrer">Resource interpreted as Document but transferred with MIME type application/pdf</a></li>
  </ul>
  
  <p><strong>My Code:</strong></p>
  
  <pre><code>function sendPdf() {
  
      $mail = new PHPMailer(true);
  
      //Server settings
      $mail-&gt;SMTPDebug = 2;                                 // Enable verbose debug output
      $mail-&gt;isSMTP();                                      // Set mailer to use SMTP
      $mail-&gt;Host = 'smtp.hostinger.com';                   // Specify main and backup SMTP servers
      $mail-&gt;SMTPAuth = true;                               // Enable SMTP authentication
      $mail-&gt;Username = 'janice@popper.ga';                 // SMTP username
      $mail-&gt;Password = 'secret';                         // SMTP password
      $mail-&gt;SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
      $mail-&gt;Port = 587;                                    // TCP port to connect to
  
      //Recipient
      $mail-&gt;SetFrom('janice@popper.ga');
      $mail-&gt;AddAddress( 'xxxxxxxx@gmail.com' );
  
      $pdf_base64 = $_POST[pdfString];
  
      //Content
      $mail-&gt;isHTML(true);                                  // Set email format to HTML
      $mail-&gt;Subject= ' New Application Form ';
      $mail-&gt;Body= ' New Application Form From WordPress site ';
  
      //Attachment
      //$mail-&gt;AddStringAttachment($pdf_base64, $_POST[clientName].'_Application.pdf', 'base64', 'application/pdf');
      //$mail-&gt;AddAttachment(dirname(__FILE__)."/Qian_Zhong_Application.pdf", 'Qian_Zhong_Application.pdf');
  
      $error = '';
  
      if(!$mail-&gt;send()){
         $error = 'Mail error: '.$mail-&gt;ErrorInfo; 
         echo $error;     
      }else{
          echo 'Message has been sent.';
      }
  
      exit; // This is required to end AJAX requests properly.
  
  }
  </code></pre>