Problem in sending mail with attachement I'm coding a small module allowing to send mail to new users with an attachement file as pdf. This pdf include all subscription details of the user.  

I generated the pdf file using FPDF and I put it (temporary) in DRUPAL_ROOT and I used two ways to send the mail:  

1) Using the hook_mail_alter:

function aos_user_pdf_mail_alter(&amp;$message) {  
  if($message['id']=='user_register_pending_approval') {  
    $attachment = array(  
     'filecontent' =&gt; file_get_contents(DRUPAL_ROOT . '/' . 'yourfilename.pdf'),  
     'filename' =&gt; 'yourfilename.pdf',  
     'filemime' =&gt; 'application/pdf'  
    );  
    $message['params']['attachments'][] = $attachment;  
  }  
}  


2) Or creating a custom function: 

function aos_user_pdf_send_mail ($mail, $uid) {  
  $user = user_load($uid);  
  $to = $mail;//gets the current user's mail address  
  $from = variable_get('site_mail', ''); //admin's mail address  
  $body = 'This is a test mail';  
  $subject = 'Your pdf';  
  $attachment = array(  
    'filecontent' =&gt; file_get_contents(DRUPAL_ROOT . '/' . 'yourfilename.pdf'),  
    'filename' =&gt; 'FILE',  
    'filemime' =&gt; 'application/pdf',   
  );  
  $message = drupal_mail('aos_user_pdf', 'message_key', $to,
    user_preferred_language($user),
    array(
      'body' =&gt; $body,
      'subject' =&gt; $subject,
      'attachment' =&gt; $attachment),
      $from,
      TRUE
    );  
}  


Unfortunately the mail is sent, but without the attachement, Please can you show me where's my mistake or an alternative way to do the job.
For sending mail with attachment you should use Mail System and Mime Mail module
Attachment functionality is built into the Mime Mail module.

After that you must set up drupal_mail() to use mime mail as the mail system interface. This is where the mail system module comes into play. The module is pretty straightforward, and lets you set a different mail system per module. There is a straightforward configuration at admin/config/system/mailsystem where you create a new setting for your module, and select mime mail as the mail system.

Assing anttatcment in variable

$message['params']['attachments']


After that you will be able to send mail with attachment.

For more information visit here