开发者

How do I send an email with a PDF attachment using rules?

I am using Drupal 6 and I installed the rules module and configured it. I need to send email with an attachment to our users.开发者_运维技巧

How do I go about doing that?


Sending pdf files is just a matter of setting mime type and stuff like that. I have some example code you can look at, for how you could do it.

$trenner  = md5(uniqid(time()));
$params = array();
$params['content_type'] = "multipart/mixed; boundary=$trenner";
$params['subject'] = $subject;
$params['body']  = "\n--$trenner\n";
$params['body'] .= "Content-Type: text/plain; charset=UTF-8; format=flowed;"."\n\n"; // sets the mime type
$params['body'] .= $message . "\n"; // Message goes here
$params['body'] .= "\n\n";
$params['body'] .= "\n\n";

$dir = file_directory_path().'/';
$pdffile = $dir.$pdffile_name;
$pdffile_mime = file_get_mimetype($pdffile);

$params['body']  .= "--$trenner"."\n";
$params['body']  .= "Content-Type:$pdffile_mime; name='$pdffile_name'\n";
$params['body']  .= "Content-Disposition: attachment; filename=$pdffile_name\n";
$params['body']  .= "Content-Transfer-Encoding: base64\n\n";
$params['body']  .= chunk_split(base64_encode($filedata));
$params['body'] .= "--$trenner--";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜