-
- 275 Posts
I'm trying to add an attachment from a snippet that sends out an email. The email is working properly however the attachment appears to be ignored. Here's what I do:
... some processing to setup the email...
// Attach the terms & conditions document to the email.
$tcFile = $modx->config['site_url'] . 'assets/documents/TC.pdf';
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $emailAddress);
$modx->mail->set(modMail::MAIL_FROM_NAME, $emailAddress);
$modx->mail->set(modMail::MAIL_SENDER, $emailAddress);
$modx->mail->set(modMail::MAIL_SUBJECT, '...']);
$modx->mail->address('to', $object->getTVValue('email'));
$modx->mail->address('reply-to', $emailAddress);
// Add the attachment
$modx->mail->mailer->AddAttachment($tcFile);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
The url to the attachment appears to be correct. When I error_log it and paste it into my browser the PDF document appears.
I'm using Revo 2.2.4.
What am I doing wrong?
Thanks.
MODx Revolution / MAMP / OS X
-
- 5,888 Posts
I think you will need the file-path, not the url
$tcFile = $modx->getOption('base_path') . 'assets/documents/TC.pdf';
-
- 275 Posts
Ah... yes...
That solved it. Thanks!!
MODx Revolution / MAMP / OS X