S
S
semki0962018-09-03 17:29:36
Drupal
semki096, 2018-09-03 17:29:36

How to programmatically send an email with an attachment, Drupal?

I do it by analogy xandeadx.ru/blog/drupal/539 , modules are installed.
My task is simpler - I want to attach a file from the site root README.txt

$attachment = array(
    'filepath' => 'README.txt'
  );
  drupal_mail('system', 'mail', '[email protected]', language_default(), array(
    'context' => array(
    'subject' => 'Some subject',
    'message' => 'Some message',
    'attachment' => $attachment
    )
  ));

Only Some message comes to the mail without an attachment. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
andead, 2018-09-03
@semki096

1. Not 'attachment' but 'attachments'
2. An array of files must be passed to 'attachments', not a filepath
3. 'attachments' must be in params, not 'context'

$attachment = array(
  'filepath' => 'README.txt'
);
drupal_mail('system', 'mail', '[email protected]', language_default(), array(
  'context' => array(
    'subject' => 'Some subject',
    'message' => 'Some message',
  ),
  'attachments' => array($attachment),
));

RTFM

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question