Mime mail system attaching two files I am trying to send pdf through using mime mail module + mailsystem module + smtp authentication module 

function send_mail(){
$to='xx@gmail.com'; $subject='xxxx'; $message='aaaaa';
$from='x123@gmail.com';
$my_mail_token = microtime();
$message = array(
'id' =&gt; $my_module . '_' . $my_mail_token,
'to' =&gt; $to,
'subject' =&gt; $subject,
'body' =&gt; array($message),
'headers' =&gt; array(
'From' =&gt; $from,
'Sender' =&gt; $from,
'Return-Path' =&gt; $from,
'Content-type' =&gt; 'text/html; charset=UTF-8',
 ),
);
 $attached=$message['params']['attachments'][]  = array(
'filename' =&gt; $filename,
'path' =&gt;DRUPAL_ROOT.'sites/default/files/pdf'.'/'.$uid.'/'.$filename,
'filecontent' =&gt; file_get_contents('sites/default/files/pdf'.'/'.$uid.'/'.$filename),
'mime' =&gt; 'application/pdf',
'Content-type' =&gt; 'application/octet-stream',
'encoding' =&gt; 'base64',
'disposition' =&gt; 'attachment',
'list' =&gt; TRUE
);
$system = drupal_mail_system($my_module, $my_mail_token);
//unlink('sites/default/files/pdf'.'/'.$uid.'/'.$filename);
$message = $system-&gt;format($message);
if ($system-&gt;mail($message)) {
return TRUE;
}
else {
return FALSE;
    }
}


This is the code its sending two files as mail attachments instead of one. Why its doing that i cant understand. Looking for help.
This happens usually when you provide both filepath and filecontent.

Please check this answer: https://drupal.stackexchange.com/a/186157