<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace">Hi,</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">
I've been trying to develop this module. It does what I need, with the exception of e-mailing a PDF file. What is wrong with my code? It gives me 'Undefined variable $attachment' and doesn't e-mail the attachment.</div>
<div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default"><div class="gmail_default"><font face="courier new, monospace">function pass2pdf_email_pdf_to_user($form) {</font></div>
<div class="gmail_default"><font face="courier new, monospace"> global $user;</font></div><div class="gmail_default"><font face="courier new, monospace"> $account = $user;</font></div><div class="gmail_default"><font face="courier new, monospace"> require(libraries_get_path('fpdf') . '/fpdf.php');</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $pdf = new FPDF();</font></div><div class="gmail_default"><font face="courier new, monospace"> $pdf->AddPage();</font></div><div class="gmail_default"><font face="courier new, monospace"> $pdf->SetFont('Arial', 'B', 16);</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $pdf->Image(theme_get_setting('logo'), 10, 6, 30);</font></div><div class="gmail_default"><font face="courier new, monospace"> $pdf->Cell(100, 100, $form['pass2pdf_pass']['#value']['pass1']);</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $pdf->Output(drupal_realpath('public://') . '/' . $form['account']['name']['#value'] . '.pdf');</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $to = $form['account']['mail']['#value'];</font></div><div class="gmail_default"><font face="courier new, monospace"> $from = variable_get('site_name') . "<" . variable_get('site_mail') . ">";</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $subject = t('Your password from @site', array('@site' => variable_get('site_name')));</font></div><div class="gmail_default"><font face="courier new, monospace"> $body = t('Hello !user. Please find your password in the attached PDF file.', array('!user' => $form['account']['name']['#value']));</font></div>
<div class="gmail_default"><font face="courier new, monospace"> $attachment = array(</font></div><div class="gmail_default"><font face="courier new, monospace"> 'filecontent' => file_get_contents(drupal_realpath('public://') . '/'. $form['account']['name']['#value'] . '.pdf'),</font></div>
<div class="gmail_default"><font face="courier new, monospace"> 'filemime' => 'application/pdf',</font></div><div class="gmail_default"><font face="courier new, monospace"> );</font></div><div class="gmail_default">
<font face="courier new, monospace"> $params['subject'] = $subject;</font></div><div class="gmail_default"><font face="courier new, monospace"> $params['body'] = $body;</font></div><div class="gmail_default">
<font face="courier new, monospace"> $params['attachment'] = $attachment;</font></div><div class="gmail_default"><font face="courier new, monospace"> $message = drupal_mail('pass2pdf', 'key', $to, user_preferred_language($user), $params, $from, TRUE);</font></div>
<div class="gmail_default"><font face="courier new, monospace"> if ($message) {</font></div><div class="gmail_default"><font face="courier new, monospace"> drupal_set_message(t('E-mail sent successfully'));</font></div>
<div class="gmail_default"><font face="courier new, monospace"> }</font></div><div class="gmail_default"><font face="courier new, monospace">}</font></div><div class="gmail_default"><font face="courier new, monospace"><br>
</font></div><div class="gmail_default"><font face="courier new, monospace">function pass2pdf_mail($key, &$message, $attachment) {</font></div><div class="gmail_default"><font face="courier new, monospace"> switch($key) {</font></div>
<div class="gmail_default"><font face="courier new, monospace"> case 'key':</font></div><div class="gmail_default"><font face="courier new, monospace"> $message['subject'] = $subject;</font></div><div class="gmail_default">
<font face="courier new, monospace"> $message['body'][] = $body;</font></div><div class="gmail_default"><font face="courier new, monospace"> $message['attachments'][] = $attachment;</font></div><div class="gmail_default">
<font face="courier new, monospace"> break;</font></div><div class="gmail_default"><font face="courier new, monospace"> }</font></div><div class="gmail_default"><font face="courier new, monospace">}</font></div><div class="gmail_default">
<font face="courier new, monospace"><br></font></div><div class="gmail_default"><font face="courier new, monospace">Regards,</font></div></div></div>