We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7231
    • 4,205 Posts
    I have a form with multiple destination options using the mailselector parameter. Is there a way to have the same email selected via the mailselector be used as the autosender address?

    I tried altering the value via the $fields[’autosender’] = "[email protected]" in an event but it did not catch. Is this possible?
      [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

      Something is happening here, but you don't know what it is.
      Do you, Mr. Jones? - [bob dylan]
      • 30223
      • 1,010 Posts
      You’re mixing up the snippet parameters with the (form) fields. That doesn’t work sadly. You can access the snippet params within an event through the $modx->event->params array but these are read only unfortunately. The only thing I can suggest for now is to duplicate the whole mail sending in the eFormOnMailSent event function.

        • 73
        • 37 Posts
        I’m trying to do a similar thing but with no joy!

        I have a ‘Copy me in’ checkbox, when checked I want it to be like setting &ccsender to 1. I’ve tried passing the field value in with the parameter like &ccsender=`[+copy+]` and a script in &eFormOnBeforeMailSent to set copy to 0 if not 1, but this sends out ccsender email in both situations even though the copy field is being adjusted!

        So I’ve followed advice above and it’s sending empty email:
        <?php
        // use with &eFormOnMailSent=`mailOut` in eForm
        
        if( !function_exists('mailOut') ) {
        	function mailOut(&$fields) {
        		# send user a copy of the report
        		if($fields['copy'] == 'yes' && $fields['email']) {
        		
        			global $modx, $from, $fromname, $subject, $report, $attachments;
        			
        			# include PHP Mailer
        			include_once "manager/includes/controls/class.phpmailer.php";
        			$mail = new PHPMailer();
        			$mail->IsMail();
        			$mail->CharSet = $modx->config['modx_charset'];
        			$mail->IsHTML(true);
        			$mail->From		= $from;
        			$mail->FromName	= $fromname;
        			$mail->Subject	= $subject;
        			$mail->Body		= $report;
        			AddAddressToMailer($mail,"to",$fields['email']);
        			AttachFilesToMailer($mail,$attachments);
        			if(!$mail->send()) return 'CCSender: ' . $_lang['ef_mail_error'] . $mail->ErrorInfo;
        		}
        		
        		return true;
        		
        	}
        }
        return '';
        
        ?>
        


        So it’s not finding the vars declared as global and you mention accessing these in the $modx->event->params array. Could you clarify how I would do this please?

        Thanks
          • 30223
          • 1,010 Posts
          <?php
          $to = $modx->event->params['to']; // you don't seem to use this in your code so you could skip this
          $from = $modx->event->params['from'];
          $fromname = $modx->event->params['fromname'];
          $subject= $modx->event->params['subject'];
          $report = $modx->event->params['report'];
          //report is a chunk or doc id so you need to load the chunk
          $report = efLoadTemplate($report);
          //you then need to replace al the placeholders in your report
          $report = formMerge($report, $fields);
          //You don't have access to the $attachments array but you can build it from the $_FILES array
          $attachments[] = $_FILES['field_name']['tmp_name'];
          $attachments[] = $_FILES['field_name_1']['tmp_name']; //repeat for each uploaded file in your form
          ?>