We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9439
    • 90 Posts
    Is it possible to send the form data as an attachment? From my Google foraging it seems that maybe you used to be able to as there appears to have been an Attachment hook at one time, but, sadly, no more.

    I can create a csv file from the form (which is the format I want) but how can that be sent in the email?

    thanks

    David Heriot
      David Heriot
      pfsmedia
      • 40706
      • 128 Posts
      You can attach Files via Hook.
      Just assign an Array as it would look like via Form Upload.

      $tmpFilename = $modx->cacheManager->getCachePath() . uniqid('formitcsv', true) . '.cache.php';
      $fields = $hook->getValues();
      
      // create CSV
      $fp = fopen($tmpFilename, 'w');
      fputcsv($fp, array_keys($fields));
      fputcsv($fp, $fields);
      fclose($fp);
      
      // attach File to FormIt
      $hook->setValue('attachment', array(
          'tmp_name' => $tmpFilename,
          'name'     => 'FormIt.csv',
          'size' => filesize($tmpFilename)
      ));
        • 9439
        • 90 Posts
        Hi Michael

        Great, thanks, I'll try this out.

        regards

        David Heriot
          David Heriot
          pfsmedia