[development] E-mail sending attachment
Paolo Mainardi
paolo at twinbit.it
Tue Dec 17 22:48:18 UTC 2013
Seems that there is a typo here:
function pass2pdf_mail($key, &$message, $attachment) {
switch($key) {
case 'key':
$message['subject'] = $subject;
$message['body'][] = $body;
$message['attachments'][] = $attachment;
break;
}
}
Must be:
function pass2pdf_mail($key, &$message, $params) {
switch($key) {
case 'key':
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
$message['attachments'][] = $params['attachment'];
break;
}
}
On Tue, Dec 17, 2013 at 11:37 PM, Muzaffer Tolga Ozses <tolga at ozses.net>wrote:
> 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,
>
--
[image: TWINBIT logo] <http://twinbit.it/>
Paolo Mainardi
*Twinbit Founder - CTO *
*www*: twinbit.it
*mobile*: (+39) 3401678089
*skype*: paolo_mainardi
*linkedin*: paolomainardi <http://www.linkedin.com/in/paolomainardi>
*twitter*: @paolomainardi <http://twitter.com/paolomainardi>
*blog*: paolomainardi.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20131217/faf5e1e9/attachment.html
More information about the development
mailing list