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

    is there a way that I can have the report emailed as an attachment in .txt format?

    My client does not have the internet or email - so I would like the eForm report to be sent to a fax number. However, for Email to fax to work, the report must be an email attachment - it won’t fax the actual email.

    Hope that makes sense.

    Thanks for your help,

    Kylie
      • 30223
      • 1,010 Posts
      You could probably achieve this by writing a function for the eFormOnBeforeMailSent or the eFormOnParse event. This function would have to compile the attachement, probably save it to a file and create and send the email using phpmailer. Here’s some starters:

      loading a template chunk and merging the form values (ie creating the body of the email / attachment):
      <?php
         $mail_template = efLoadTemplate('someChunk');
         $body = formMerge($mail_template,$fields); 
      ?>
      


      The code for sending email could be something like this:
      <?php
      include_once "manager/includes/controls/class.phpmailer.php";
         $mail = new PHPMailer();
         $mail->IsMail();
         $mail->CharSet = $modx->config['modx_charset'];
         $mail->IsHTML($isHtml);
         $mail->From  = '[email protected]';
         $mail->FromName   = 'Some Name';
         $mail->Subject   = $fields['subject'];
         $mail->Body      = $mail_body;
         AddAddressToMailer($mail,"to",$fields['email']);
         AttachFilesToMailer($mail,$attachment); //$attachment would point to the file you created
         if(!$mail->send()) $fields['validationmessage'] = 'Unable to send mail at this time. Please try again later';
      ?>


      You would use this inside an event function. Read the eform documentation and samples in the eform/docs/ folder and browse the wiki to learn more about using eform events.

      Good luck