title: Email attachment issue in a timer task in ProcessMaker
body: <p>We have been working on implementing some business processes using ProcessMaker. We have been observing an issue regarding attachments in sending email through ProcessMaker. </p>
  
  <p>Here is the issue in detail.</p>
  
  <ol>
  <li><p>We have a timer task in which it sends some emails to business users with some attachment produced by PM. But we have been observing that emails are sent sometimes without attachment but sometimes email contains attachment. </p></li>
  <li><p>To dig down the problem we have checked each step before sending email but we have found that attachment file exists before sending email.</p></li>
  <li><p>In any process flow, email sending with attachment is working perfectly. But for timer task sometimes emails are sent without attachment and sometimes email is sent without attachment.</p></li>
  <li><p>Following is the code block which is executed on trigger of the timer task.</p>
  
  <pre><code>@%emailCounter++;
  
  try{
  
      $to = 'xxxx@gmail.com';
  
      $caseId = @@APPLICATION;
  
      $aAttachments = [];
  
      @@debugStr = "";
  
      @@fileQuery = "select `APP_DOC_UID`, `DOC_VERSION` FROM `APP_DOCUMENT` where `APP_UID`='$caseId' order by `DOC_VERSION` desc limit 1";
      $aFiles = executeQuery(@@fileQuery);
  
      @@debugStr .= ";&lt;br/&gt; File counts = ".count($aFiles);
  
      foreach ($aFiles as $aFile)
      {
          @@debugStr .= ";&lt;br/&gt; File = ".$aFile['APP_DOC_UID'];
  
          $oDoc = new AppDocument();
          $aDocInfo = $oDoc-&gt;Load($aFile['APP_DOC_UID'], $aFile['DOC_VERSION']);
  
          @@debugStr .= ";&lt;br/&gt; File Info = ".json_encode($aDocInfo);
  
          $ext = '.pdf';  //set to '.doc' if sending a DOC file
          $g = new G();
          $pathToFile = PATH_DOCUMENT . $g-&gt;getPathFromUID(@@APPLICATION) . PATH_SEP . 'outdocs' .  PATH_SEP . $aFile['APP_DOC_UID'] . '_' . $aDocInfo['DOC_VERSION'] . $ext;
          @@debugStr .= ";&lt;br/&gt; File path = ".$pathToFile;
          $filename = @@selfNamePDF;
  
          $aAttachments = PMFAddAttachmentToArray($aAttachments, $filename, $pathToFile);
  
      }
  
      @@subjectLine = '[Test - attachment] '.@@title;
  
      PMFSendMessage(@@APPLICATION, 'yyyy@zzz.com', $to , 'pppp@gmail.com','' , @@subjectLine, 'TestEmail.html', array(), $aAttachments);
  
  } catch (Exception $e) {
      PMFSendMessage(@@APPLICATION, 'yyyy@zzz.com', $to , 'mmmm@gmail.com','' , 'Exception Occured - '.$e-&gt;getMessage(), 'TestEmail.html', array(), $aAttachments);
  }
  </code></pre></li>
  </ol>
  
  <p>Looking for a direction in which we can think to get rid of this problem.</p>