【问题标题】:MimeMail: issue with attachmentsMimeMail:附件问题
【发布时间】:2011-03-17 15:13:18
【问题描述】:

我在 Drupal 中使用 mimemail 模块来发送带有附件的电子邮件。电子邮件已正确发送,但附件未正确发送。这是我使用的代码(我刚刚启用了模块):

$sender = 'mycompany@company.com';
$recipient = 'myemail@mail.com';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[]=array(         
  'filepath' => 'invoices/sample.pdf',
  'filemime' => 'application/pdf',
);

mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);

为了确保 pdf 附件的路径正确,我写了这一行来从浏览器下载附件并且它可以工作。

header('Location: invoices/sample.pdf');

另外,我已经尝试过这个替代代码。但是还是什么都没有……

$file = new stdClass();
$file->filename = 'sample.pdf';
$file->filepath = 'invoices/sample.pdf';
$file->filemime = 'application/pdf';
mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, array($file), $mailkey);

ps。我不这么认为,但可能是因为我的主机不允许发送附件? 谢谢

【问题讨论】:

  • 您是否尝试过使用绝对文件路径而不是invoices/sample.pdf
  • 是的,我已经尝试了所有可能的路径...我网站的根目录/invoices...也是完整的domain.com/invoices...是$attachments 声明并传递给milemail功能 ?我真的被困在这上面了,啊

标签: php drupal drupal-6 mime-mail


【解决方案1】:

为 Mime 邮件模块打开了两个问题报告。

Attachments specified with absolute local paths are not added 中,OP 报告使用绝对路径指定的附件不起作用;有一个建议的补丁来解决这个问题。在那个问题中,建议更改代码以发送带有附件的电子邮件

header('Location: invoices/sample.pdf');

$sender = 'mycompany@company.com';
$recipient = 'myemail@email.com';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[] = array(
  'filepath' => 'invoices/sample.pdf',
  'filemime' => 'mime/type',
);

mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);

header('Location: invoices/sample.pdf');

$sender = 'mycompany@company.com';
$recipient = 'myemail@email.com';
$subject = 'New order';
$body = 'Please, see the attachment.';
$plaintext = TRUE;
$headers = array();
$attachments[] = array(
  'filepath' => 'invoices/sample.pdf',
  'filemime' => 'mime/type',
  'filename' => 'sample.pdf',
  'list' => TRUE,
);

mimemail($sender, $recipient, $subject, $body, $plaintext, $headers, $text = NULL, $attachments, $mailkey);

mimemail + smtp + attachments not working with attachments 中,OP 报告使用 SMTP 时不显示附件;在同一个报告中,另一个用户报告他没有使用 SMTP,但是通过规则发送电子邮件时,附件没有显示。

【讨论】:

  • 在 Drupal 中调用的正确函数,与header() 的效果相同,是drupal_set_header(),它将设置的标头存储在静态变量中,并返回已经设置的标头。
猜你喜欢
  • 2011-08-07
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 2016-07-17
  • 2011-09-10
  • 2010-10-31
  • 1970-01-01
  • 2018-08-25
相关资源
最近更新 更多