title: Error when sending mail with attachment using PHP mailer: Transaction failed: Missing start boundary SMTP code: 554
body: <p>Im trying to send php mailer email with pdf attachment and its showing this error:
  E-mail not sent. Error: SMTP Error: data not accepted.SMTP server error: DATA END command failed Detail: Transaction failed: Missing start boundary
   SMTP code: 554</p>
  
  <p>I tried to add mime boundaries all over the place, but had same result.</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  include dirname(__FILE__) . '/../views/pdf-receipt.php';
  
  function sendMailTest(
      $recipient_mail, $recipient_name, $from_mail, $from_name, $subject, $body, $body_without_html, $attachments=NULL
  ) {
      require 'folder/PHPMailer-5.2.26/PHPMailerAutoload.php';
      $mail = new PHPMailer;
  
      try {
          $mail-&gt;isSMTP();
          $mail-&gt;setFrom($from_mail, $from_name);
          $mail-&gt;addAddress($recipient_mail, $recipient_name);
          $mime_boundary = "Name of company".md5(time());
          $mail-&gt;SMTPDebug = true;
          $mail-&gt;Host = 'email-smtp.eu-west-1.amazonaws.com';
          $mail-&gt;Username = 'XXX';
          $mail-&gt;Password = 'XXX';
  
          $mail-&gt;Encoding = 'quoted-printable';
          $mail-&gt;addCustomHeader('Content-ID', '20cca', 'Content-Type', 'multipart/mixed', 'boundary='.$mime_boundary.'\n');
          $mail-&gt;Body = "--$mime_boundary\n";
  
          $mail-&gt;CharSet = 'UTF-8';
          $mail-&gt;Subject = utf8_encode($subject);
  
          $mail-&gt;Body .= "Hey\n";
  
          $mail-&gt;AltBody .= "--$mime_boundary\n".$body_without_html;
  
          $mail-&gt;SMTPAuth = true;
  
          $mail-&gt;SMTPSecure = 'tls';
          $mail-&gt;Port = 000;
  
          $mail-&gt;isHTML(true);
          $data = '%PDF-1.2 6 0 obj &lt;&lt; /S /GoTo /D (chapter.1) &gt;&gt;';       
          // if i comment line below email is sent properly, 
          // if i use AddAttachment local pdf file its working also, 
          // but i use TCPD generated PDF and attaching it, if i will 
          // just write it out to the message body i will see it as a 
          // text or if i will attach 'addStringEmbeddedImage' its 
          //displayed correctly but on same line as message text
  
          // $attachments is pretty much this:
          // $pdf-&gt;Output("test.pdf", "S");
          // tried this $mail-&gt;Body .= "--$mime_boundary\n"; before next line
          // did not help
          $mail-&gt;AddStringAttachment($attachments, 'base64', 'application/pdf');
  
          if($mail-&gt;send()) {
              return;
          }
      } catch (Exception $e) {}
  
      echo 'E-mail not sent. Error: ', $mail-&gt;ErrorInfo, PHP_EOL;
  }
  ?&gt;
  </code></pre>
  
  <p>I expect email to be sent with attachment but see no starting boundary error.</p>