How do I send a mail with attachment?
Drupal core doesn't support mail attachments/HTML mails.

You need to use an alternative mail implementation, like the Swift Mailer module. 

Also, the reason the first implementation doesn't work is because you need to go through a hook_mail() implementation instead. See how core does it.