We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44649
    • 68 Posts
    Hi,

    I'm trying to attach a file to the email sent from FormIt once a submission has been made, I've tried:
    https://forums.modx.com/index.php?action=thread&thread=58712&i=1
    https://docs.modx.com/extras/revo/formit/formit.hooks/formit.hooks.formitautoresponder

    However I still can't seem to get the file to attach to the email.

    FormIt Call:
    [[!FormIt?
    &hooks=`spam,Attachment,email,redirect`
    &emailTpl=`email-briefing-tpl`
    &emailUseFieldForSubject=`1`
    &emailFromName=`Briefing Form`
    &emailTo=`[email protected]`
    &submitVar=`briefing`
    &emailBCC=``
    &redirectTo=`27`
    &validate=`
    name:required
    `
    ]]


    Basic Form Code:
    <form id="contact_form" action="[[~[[*id]]]]" method="post" class="custom" enctype="multipart/form-data">
        <span class="error">[[!+fi.error.name]]</span>
        <input type="text" name="name" id="name" value="[[!+fi.name]]" placeholder=""/> 
        <input type="submit" name="briefing" value="Submit">
    </form>


    Attachment Snippet:
    <?php
    $attachment = 'http://www.absoluteurl.com/pdf.pdf';
    $hook->modx->getService('mail', 'mail.modPHPMailer');
    $hook->modx->mail->mailer->AddAttachment($attachment);
    return true;


    If anyone has any suggestions!

    Thanks
      • 38783
      • 571 Posts
      It looks like the answer might be in here somewhere? https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form

      At the end of the thread I noticed that the attachment snippet uses a local server path to the file.

      $attachment = '/tmp/***.***';


        If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

        email: [email protected] | website: https://andytough.com
        • 44649
        • 68 Posts
        I tried running it from a local path '/assets/pdf/pdf.pdf' and no joy unfortunately
          • 38783
          • 571 Posts
          I was thinking more along the lines of the path to the folder in the local server environment. This would vary depending on your hosting environment but might be something like this on a shared host...

          $attachment = '/www/www/filename.pdf';


          or if you are running your own Linux server...

          $attachment = '/var/www/vhosts/yourdomainname.com/httpdocs/pdfs/filename.pdf';

            If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

            email: [email protected] | website: https://andytough.com
            • 44649
            • 68 Posts
            Ah I should of seen that from the tmp folder name, just tried on a site hosted on Linux using Plesk
            <?php
            $attachment = '/httpdocs/assets/uploads/cpw_christmas_products_day_0479.jpg';
            $hook->modx->getService('mail', 'mail.modPHPMailer');
            $hook->modx->mail->mailer->AddAttachment($attachment);
            return true;


            And on local machine running XAMPP
            <?php
            $attachment = 'Applications/XAMPP/xamppfiles/htdocs/dannys/assets/uploads/cpw_christmas_products_day_0479.jpg';
            $hook->modx->getService('mail', 'mail.modPHPMailer');
            $hook->modx->mail->mailer->AddAttachment($attachment);
            return true;


            Still not attaching the file, the email comes through with all the other fields just not the file!
              • 38783
              • 571 Posts
              Is there anything in the MODX error log?

              Manage > Reports > Error log
                If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                email: [email protected] | website: https://andytough.com
                • 44649
                • 68 Posts
                No errors in PHP log or MODX error log on localhost and Linux server
                  • 37105
                  • 194 Posts
                  Try to put the hook Attachment after the hook email so your FormIt call becomes like this.

                  [[!FormIt?
                  &hooks=`spam,email,Attachment,redirect`
                  &emailTpl=`email-briefing-tpl`
                  &emailUseFieldForSubject=`1`
                  &emailFromName=`Briefing Form`
                  &emailTo=`[email protected]`
                  &submitVar=`briefing`
                  &emailBCC=``
                  &redirectTo=`27`
                  &validate=`
                  name:required
                  `
                  ]]
                    Codeplaza Webdesign: for professional websites at low cost
                    • 44649
                    • 68 Posts
                    Tried with attachment after email:
                    &hooks=`spam,email,Attachment,redirect`


                    Still no joy, no error messages.

                    I'm going to try and a fresh install of MODX one more time, and if it doesn't work I guess I'll have to use custom mail code.
                      • 28432
                      • 372 Posts
                      Hi,

                      If you want just to send file with the email, normally you need to add in you form call
                      enctype="multipart/form-data"


                      Then add a file type field
                      <input name="myFile" id="myFile" value="" type="file">


                      And (last) in your email TPL (email-briefing-tpl) add this field
                      [[+myFile]]


                      I hope this help.