我找不到附件有什么问题。电子邮件是空的。 这是针对drupal 7定制的webform。这是我的代码:
<?php
module_load_include('inc', 'print_pdf', 'print_pdf.pages');
$file_content = module_invoke('print_pdf', 'generate_path', '/****.pdf');
$attachment = array(
'filecontent' => $file_content,
'filename' => '****.pdf',
'filemime' => 'application/pdf',
'list' => TRUE
);
$message = array(
'headers' => array('Content-Type' => 'text/html'),
'key' => 'test',
'to' => '****@****.com',
'from' => '****@****.com',
'attachments' => $attachments,
'subject' => 'Test email',
'body' => 'test'
);
$system = drupal_mail_system('mimemail', 'test');
$system->format($message);
$result = $system->mail($message);
?>
答案 0 :(得分:0)
尝试检查路径并访问文件。
我使用此代码将非托管文件作为附件发送到Mimemail和MailSystem:
/**
* Send email with attachment
*/
mymodule_send('default', array(
'params' => array(
'subject' => 'Mail suject',
'body' => '<p>Mail body</p>',
'attachments' => array(
array(
'filename' => 'HumanreadableFileName.xls',
'filemime' => 'application/vnd.ms-excel', // xls mime
'filepath' => 'public://2016-04-18_report.xls', // path to file
),
),
),
), 'john@doe.com');
/**
* Implements hook_send().
*/
function mymodule_send($key, $params = array(), $to = NULL, $from = NULL) {
if (!valid_email_address($to)) {
$to = variable_get('site_mail', ini_get('sendmail_from'));
}
drupal_mail('snabmail', $key, $to, language_default(), $params, $from);
}