We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27519
    • 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
      • 4172
      • 5,888 Posts
      I think you will need the file-path, not the url

      $tcFile = $modx->getOption('base_path') . 'assets/documents/TC.pdf';
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 27519
        • 275 Posts
        Ah... yes... undecided That solved it. Thanks!!
          MODx Revolution / MAMP / OS X