On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi,

    I was wondering how hard it would it to be include a time stamp, IP address and user agent in an email sent using eform?


    Thanks
    • Here is the eForm event function that I use to do this:
      <?php
      function addUserInfo(&$fields){
      
      /* Runs on eFormOnBeforeMailSent event 
       * Called before the message is sent. This function is called regardless of whether &noemail is set */
      
      if(isset($_SERVER['REMOTE_HOST'])) $fromhost=$_SERVER['REMOTE_HOST'].' ('.$_SERVER['REMOTE_ADDR'].')';
      else $fromhost=gethostbyaddr($_SERVER['REMOTE_ADDR']).' ('.$_SERVER['REMOTE_ADDR'].')';
      $userInfo='<p>
      From: '.$fromhost.'<br />
      Using: '.$_SERVER['HTTP_USER_AGENT'].'
      </p>';
      $fields['userInfo']=$userInfo;
      
      }
      
      return '';
      ?>


      I don’t include a timestamp because the email itself has one, but you could easily do that if you like.

      Save this code as a snippet and call it on your form page before the eForm snippet call. In your eForm snippet call add &eFormOnBeforeMailSent=`addUserInfo`. And make sure that you have the [+userInfo+] placeholder at the end of your email template.

      eForm event functions are the bomb!
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
      • Excellent, thanks very much!