【问题标题】:Drupal email is empty. What is wrong with my attachment?Drupal 电子邮件为空。我的附件有什么问题?
【发布时间】:2016-04-13 09:16:52
【问题描述】:

我找不到附件有什么问题。电子邮件是空的。 这适用于 drupal 7 自定义网络表单。这是我的代码:

<?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);

?> 

【问题讨论】:

    标签: php email drupal-7 attachment


    【解决方案1】:

    尝试检查文件的路径和访问权限。

    我使用此代码通过 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);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-03-05
      • 1970-01-01
      • 1970-01-01
      • 2013-07-31
      • 2011-12-05
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多