We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I am working on a site that needs to send 3 differend emails to 3 differend adresses at once and also I need to send 3 mails at once to 1 mailadres.

    i like to inform the admin and the sender and the reciver all with cusom mails like the admin needs more info than the reciver and the sender only needs a mail saing that the request was send including some info.

    And i like to send out 3mails to the one that fills in the form (thats on another page), the mail needs to have a contract a manual and a bankform that the form filler needs to fill in and sign then mail, to get access to a part of the site.

    so multiple reportchunks would be a nice option for eform.

    Greets Dimmy
      follow me on twitter: @dimmy01
      • 30223
      • 1,010 Posts
      Hi Dimmy,

      In my next major version of eForm I’m attempting to introduce multiple templates for the form as well as the report, mainly aimed at multi-page forms, but as usual people will surely find other creative uses. However that is going to be a while as development is stalled while I’m moving house and setting up a new art studio/workshop.

      The problem with multiple report templates is how you are going to associate each report template with each email. Even in the new version you’d have to do some custom scripting. There are ways you can approach this now in the current version.

      1. Add extra (custom) parameters to the snippet call (eg &reportContract=`contractReport` &reportBankForm=`bankFormReport`). These extra parameters are not directly visible to eForm but you access them via script.

      2. In the eformOnBeforeMailSent event function (that you will have to write) do something like this.
      <?php
      function onBeforeMailSentFunction( &$fields ){
          global $modx, $_lang;
      
          //get the extra parameters
          $reportBankForm = $modx->event->params['reportBankForm'];
          $reportContract = $modx->event->params['reportContract'];
      
          //load the templates
          $reportBankForm = (($tmp=efLoadTemplate($report))!==false)?$tmp:$_lang['ef_no_report'] . " '$report'";
          $reportContract = (($tmp=efLoadTemplate($report))!==false)?$tmp:$_lang['ef_no_report'] . " '$report'";
         
          //prepare mail variables (duplicating eForm code)
          $sendAsText = $modx->event->params['sendAsText'];
          $isHtml = ($sendAsText==1 || strstr($sendAsText,'report'))?false:true;    
          $fields['disclaimer'] = ($modx-event->params['disclaimer'])? formMerge($modx-event->params['disclaimer'],$fields):"";
          $subject	= isset($fields['subject'])?$fields['subject']:(($modx-event->params['subject'])? formMerge($modx-event->params['subject'],$fields):$modx-event->params['category']);
          $fields['subject'] = $subject; //make subject available in report & thank you page
          $from = ($modx-event->params['from'])? formMerge($modx-event->params['from'],$fields):"";
          $fromname	= ($modx-event->params['fromname'])? formMerge($modx-event->params['fromname'],$fields):"";
      
          //merge placeholders
          $reportBankForm = formMerge($reportBankForm,$fields);
          $reportContract = formMerge($reportContract,$fields);
      
          //sent bank form mail  
              $mail = new PHPMailer();
              $mail->IsMail();
              $mail->CharSet = $modx->config['modx_charset'];
              $mail->IsHTML($isHtml);
              $mail->From = $from
              $mail->FromName	= $fromname;
              $mail->Subject	= $subject;
              $mail->Body = $reportBankForm;
              AddAddressToMailer($mail,"to",$fields['bankform_mail_address_here']);
              if(!$mail->send())  $fields['validationmessage'] .= 'Bank Form mail failed to send. Error:' . $mail->ErrorInfo;
      
           //sent contract mail  
              $mail = new PHPMailer();
              $mail->IsMail();
              $mail->CharSet = $modx->config['modx_charset'];
              $mail->IsHTML($isHtml);
              $mail->From = $from
              $mail->FromName	= $fromname;
              $mail->Subject	= $subject;
              $mail->Body = $reportContract;
              AddAddressToMailer($mail,"to",$fields['contract_mail_address_here']);
              if(!$mail->send())  $fields['validationmessage'] .= 'Contract mail failed to send. Error:' . $mail->ErrorInfo;
          
          
        return true;  
      
      }
      
      //snippet returns
      return '';
      ?>
      


      Not tested but this should lead you to a solution. I’m sure it can be improved upon. As you can see there’s quite a bit of duplicating eForm code. The event structure is a bit limited sometimes (something I’m aiming to address). The function (and the events) have very limited error reporting possibilities. The best I could come up with quickly is to add to the $fields[’validationmessage’]. You’d have to add the [+validationmessage+] placeholder in your &thankyou template somewhere to see it.

      Good luck.
        • 7455
        • 2,204 Posts
        Thanks Toby will look in to this looks promissing.
          follow me on twitter: @dimmy01