Tutorial :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--";  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »