Attach documents (e.g. Terms and conditions) to Drupal Commerce Message order confirmations

Drupal Commerce Message

Attaching documents like PDFs to Drupal eMails is quite simple. For our specific case we needed to attach PDF documents to Drupal Commerce Message order confirmations.

This can easily be done using the hook below. Simply modify the names and path to the document to attach. That's it!

  1. function MY_MODULE_mail_alter(&$message) {
  2.     if ($message['id'] == 'message_notify_commerce_order_order_confirmation') {
  3.         $file = file_create_url('public://media/my-document-to-attach.pdf');
  4.         $attachment = array(
  5.             'filecontent' => file_get_contents($file),
  6.             'filename' => 'test.pdf',
  7.             'filemime' => 'application/pdf',
  8.         );
  10.         $message['params']['attachments'][] = $attachment;
  11.     }
  12. }


Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen