Muzaffer Tolga Ozses
2013-12-17 22:37:13 UTC
Hi,
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.
function pass2pdf_email_pdf_to_user($form) {
global $user;
$account = $user;
require(libraries_get_path('fpdf') . '/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Image(theme_get_setting('logo'), 10, 6, 30);
$pdf->Cell(100, 100, $form['pass2pdf_pass']['#value']['pass1']);
$pdf->Output(drupal_realpath('public://') . '/' .
$form['account']['name']['#value'] . '.pdf');
$to = $form['account']['mail']['#value'];
$from = variable_get('site_name') . "<" . variable_get('site_mail') . ">";
$subject = t('Your password from @site', array('@site' =>
variable_get('site_name')));
$body = t('Hello !user. Please find your password in the attached PDF
file.', array('!user' => $form['account']['name']['#value']));
$attachment = array(
'filecontent' => file_get_contents(drupal_realpath('public://') . '/'.
$form['account']['name']['#value'] . '.pdf'),
'filemime' => 'application/pdf',
);
$params['subject'] = $subject;
$params['body'] = $body;
$params['attachment'] = $attachment;
$message = drupal_mail('pass2pdf', 'key', $to,
user_preferred_language($user), $params, $from, TRUE);
if ($message) {
drupal_set_message(t('E-mail sent successfully'));
}
}
function pass2pdf_mail($key, &$message, $attachment) {
switch($key) {
case 'key':
$message['subject'] = $subject;
$message['body'][] = $body;
$message['attachments'][] = $attachment;
break;
}
}
Regards,
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.
function pass2pdf_email_pdf_to_user($form) {
global $user;
$account = $user;
require(libraries_get_path('fpdf') . '/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 16);
$pdf->Image(theme_get_setting('logo'), 10, 6, 30);
$pdf->Cell(100, 100, $form['pass2pdf_pass']['#value']['pass1']);
$pdf->Output(drupal_realpath('public://') . '/' .
$form['account']['name']['#value'] . '.pdf');
$to = $form['account']['mail']['#value'];
$from = variable_get('site_name') . "<" . variable_get('site_mail') . ">";
$subject = t('Your password from @site', array('@site' =>
variable_get('site_name')));
$body = t('Hello !user. Please find your password in the attached PDF
file.', array('!user' => $form['account']['name']['#value']));
$attachment = array(
'filecontent' => file_get_contents(drupal_realpath('public://') . '/'.
$form['account']['name']['#value'] . '.pdf'),
'filemime' => 'application/pdf',
);
$params['subject'] = $subject;
$params['body'] = $body;
$params['attachment'] = $attachment;
$message = drupal_mail('pass2pdf', 'key', $to,
user_preferred_language($user), $params, $from, TRUE);
if ($message) {
drupal_set_message(t('E-mail sent successfully'));
}
}
function pass2pdf_mail($key, &$message, $attachment) {
switch($key) {
case 'key':
$message['subject'] = $subject;
$message['body'][] = $body;
$message['attachments'][] = $attachment;
break;
}
}
Regards,