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

    is there any other plugins or snippets for preventing email spam, the Anti-Spam Email Plugin seems to be broken in new versions of modx.


    http://modxcms.com/forums/index.php?topic=6444
      • 30223
      • 1,010 Posts
      The best way of preventing spam is not to publish email addresses on your web site at all but instead point people to a contact form on your site.
        • 10357
        • 573 Posts
        Hi,

        the problem is I need to provide over 10 different addresses.
          • 30223
          • 1,010 Posts
          Have a look at eForm..

          It’s easy to make a contact form where you can choose from 10 or more names/email addresses without the email addresses showing up on your page (or in the source). Look for the &to parameter which can be set to a list of email addresses and the &mailselector parameter which you can point to a select field with a numeric index that relates to the mail addresses in the &to parameter.

          You can easily extend eform with a snippet so that you can build links on your site that will set up the contact form for one particular address out of the list ( something like contact.html?mailto=2 )

          If you’re interested I’ll help you along.. otherwise you’ll have to wait for someone to help you with the anti-spam email plugin.
            • 10357
            • 573 Posts
            I really like your snippet idea, I am by no means a php coder so any help would be greatly appreciated.

              • 30223
              • 1,010 Posts
              Ok, first of all have a look at the eForm documentation and make yourself a contact form. eForm by default is already installed but you may want to get the latest version using the link I provided above. Once installed have look in the folder assets/snippets/eform/docs/ and open eform.htm. Read through all teh documentation and using the examples you should be able to get yourself a contact form going. (Chances are if you’re running MODx 0.9.5 and you’ve installed the demo site, there’s already a contact form based on eForm)

              No php knowledge required so far!

              Let me know how you are going... We’ll extend it from there...

              There’s also some more tips in the wiki

              EDIT: As it’s rather late at night I’m not likely to respond for a while. Closing my eyes! Give you time to fiddle some smiley
                • 10357
                • 573 Posts
                Hi,

                many thanks for your help with this grin

                I have used eForm quite a bit already.. here is what i have so far:

                [!eForm? &formid=`contactForm` &subject=`[Contact Form]` &tpl=`contactForm` &report=`contactReport` &gotoid=`40` &sendAsHtml='1' &replyto=`email` &to =`[email protected],[email protected],[email protected]` &mailselector=`toSend` !]


                and my template:

                [+validationmessage+]
                <form method="post" action="[~[*id*]~]" id="contactForm" >
                <fieldset>
                <p class="legend">Contact form:</p>
                               <dl class="details">
                		<dt> <input name="formid" type="hidden" value="contactForm" /> </dt>
                                <dt><label for="cfName">Full Name:</label></dt>
                		<dd><input name="name" id="cfName"  type="text" size="30" eform="Full name::1:" /></dd>
                
                		<dt><label for="cfEmail">Email: </label></dt>
                		<dd><input name="email" id="cfEmail" type="text" size="30" eform="Email Address:email:1" /></dd>
                
                		<dt><label for="cfTelephone">Telephone:</label></dt>
                		<dd><input name="tel" id="cfTelephone"  type="text" size="30" eform="Telephone::1:"/></dd>
                
                		<dt> <label for="cfMessage">Message:</label></dt>
                		<dd><textarea  name="Message"  cols="35" rows="6"  id="cfMessage" eform="Message:textarea"></textarea></dd>
                
                  </dl>
                </fieldset>
                 <p><input type="submit" name="submit" value="Send Feedback"></p>
                 </form>


                Enjoy your sleep ! smiley
                  • 30223
                  • 1,010 Posts
                  Ok, a bit of a long post but this should get you going... You’re well on your way with what you have there. The only thing missing from your form template as you posted would be the toSend field. Normally you’d have something like this somewhere in your form:

                        <dt><label accesskey="s" for="cfToSend">Recipient:</label></dt>
                        <dd><select name="toSend" id="cfToSend" eform="Recipient::1">
                           <option value="1">Sales</option>
                           <option value="2">Support</option>
                           <option value="3">Billing</option>
                        </select></dd>
                  


                  This should be all you need to create a generic contact form where the user can select the recipient. However we can enhance this so you could have links such as this on your site leading to the same form without displaying the recipient dropdown (select) box.
                  <a href="contact.html?mailto=3">Contact our Billing Department</a>
                  


                  To do this you need to first of all create an extra snippet, call it contactFormFunctions and paste the below script:
                  <?php
                  function onBeforeParseFunction(&$fields,&$templates){
                     global $modx;
                     //fetch the email addresses from the eform parameters
                     $addresses = explode(',', $modx->event->params['to']);
                     //add dummy to correct index
                     array_unshift($addresses,$addresses[0]);
                     
                     //make sure this array contains (at least) the same number of elements as you have
                     //addresses in the &to parameter
                     $select_subjects = array(
                        1 => 'Sales',
                        2 => 'Support',
                        3 => 'Billing'
                     );
                     
                     $email_index = 0; //initialize
                     
                     if( isset($_GET['mailto']) ){
                        $email_index = abs($_GET['mailto']);  //array index is 1 lower then email index
                        $_SESSION['eform_mailto'] = $email_index; //remember value
                     }elseif( isset($_SESSION['eform_mailto']) )
                        $email_index = $_SESSION['eform_mailto'];
                  
                     if( $email_index > 0 ){
                        //make sure address index exists or make it the first one in the list
                        $email_index = ( isset($addresses[$email_index]) ) ? $email_index : 1;
                        $mail_tag = '<dt><input type="hidden" name="toSend" value="'.$email_index.'" /></dt>';
                     }else{
                        //Display a select tag with all addresses
                       $mail_tag = '
                       <dt><label accesskey="s" for="cfToSend">Recipient:</label></dt>
                       <dd><select name="toSend" id="cfToSend" eform="Recipient::1">';
                       for($i=1;$i<(count($addresses));$i++){
                          //just in case there's a discrepancy between subjects array and email addresses
                          $subject = ( isset($select_subjects[$i]) ) ? $select_subjects[$i] : ucfirst(implode(' ',explode('.',substr($addresses[$i],0,strpos($addresses[$i],'@')))));
                          $mail_tag .= "\n\t". '<option value="'.$i.'">'.$subject.'</option>';
                       }   
                       $mail_tag .= '</select></dd>';
                     }
                     
                     $templates['tpl'] = str_replace('[+mailaddress_tag+]',$mail_tag,$templates['tpl']);
                     
                     return true; 
                  }
                  
                  function onBeforeMailFunction( &$fields ){
                     //successfully submitted form so destroy session variable
                     unset($_SESSION['eform_mailto']);
                     return true;
                  }
                  
                  return ''; //return empty value from snippet
                  ?>
                  


                  Next you need to adjust your form template and instead of the select tag insert a [+mailaddress_tag+] placeholder. This will be replaced with either a select tag or a hidden input tag, depending on how you arrive at the contact form. More about that in a moment. So your form template should now look like this:
                  [+validationmessage+]
                  <form method="post" action="[~[*id*]~]" id="contactForm" >
                  <fieldset>
                  <p class="legend">Contact form:</p>
                                 <dl class="details">
                  		<dt> <input name="formid" type="hidden" value="contactForm" /> </dt>
                                  
                                  [+mailaddress_tag+]
                  
                                  <dt><label for="cfName">Full Name:</label></dt>
                  		<dd><input name="name" id="cfName"  type="text" size="30" eform="Full name::1:" /></dd>
                  
                  		<dt><label for="cfEmail">Email: </label></dt>
                  		<dd><input name="email" id="cfEmail" type="text" size="30" eform="Email Address:email:1" /></dd>
                  
                  		<dt><label for="cfTelephone">Telephone:</label></dt>
                  		<dd><input name="tel" id="cfTelephone"  type="text" size="30" eform="Telephone::1:"/></dd>
                  
                  		<dt> <label for="cfMessage">Message:</label></dt>
                  		<dd><textarea  name="Message"  cols="35" rows="6"  id="cfMessage" eform="Message:textarea"></textarea></dd>
                  
                    </dl>
                  </fieldset>
                   <p><input type="submit" name="submit" value="Send Feedback"></p>
                   </form>
                  


                  The last thing you need to do is to add a snippet call to the new contactFormFunctions snippet and to adjust your snippet call for including the eFormOnBeforeFormParse and the eFormOnBeforeMailSent events. Here’s the new calls:
                  (I’ve placed the parameters on separate lines for clarity but you must have all parameters on one line when copying/pasting - as you had before)
                  [[contactFormFunctions]]
                  [!eForm? 
                      &formid=`contactForm` 
                      &subject=`[Contact Form]` 
                      &tpl=`contactForm` 
                      &report=`contactReport` 
                      &gotoid=`40` 
                      &sendAsHtml='1' 
                      &replyto=`email` 
                      &to =`[email protected],[email protected],[email protected]` 
                      &mailselector=`toSend` 
                      &eFormOnBeforeFormParse=`onBeforeParseFunction` 
                      &eFormOnBeforeMailSent=`onBeforeMailFunction`
                  !]
                  


                  This should now allow you to have links to the contact form like this:
                  contact.htm -> shows contact form with a recipient dropdown list
                  contact.htm?mailto=3 -> contact form without dropdown list and preset to 3rd email address (billing)
                  etcetera.

                  To increase the number of recipients in the list you need to adjust the &to parameter and add elements to the $select_subjects array in the onBeforeParseFunction of the contactFormFunctions snippet. The $select_subjects array looks like this:

                  <?php
                  $select_subjects = array(
                        1 => 'Sales',
                        2 => 'Support',
                        3 => 'Billing'
                     );
                  ?>
                  

                  As you said you’re not a php coder, Just remember to add comma’s after each array element except the last one!

                  Good luck
                    • 10357
                    • 573 Posts
                    Thank you grin it works perfectly. I bet a lot of people will find this very useful.

                    One small tweak; Is is possible to display who you are emailing above the contact form?

                    many thanks again,
                    Gareth
                      • 21496
                      • 225 Posts
                      Quote from: g5604 at Feb 24, 2007, 06:57 AM

                      is there any other plugins or snippets for preventing email spam, the Anti-Spam Email Plugin seems to be broken in new versions of modx.

                      http://modxcms.com/forums/index.php?topic=6444

                      I was wondering why it should be broken, since I’m using that plugin. So I was checking that thread mentioned above, and I was learning there is only a problem when providing a subject with spaces. What actually wasn’t that difficult to fix, it’s a problem with the regex. Replacing the last line with this code should do it:

                      $modx->documentOutput=preg_replace_callback("#<a[^>]*mailto:([^'\"]*)['\" ]>([^<]*)</a>#i", emailaddress, $modx->documentOutput);


                      Special characters like umlauts still don’t work, but I guess that could also be fixed if really necessary.

                      My philosophy is that it should be made as easy as possible for visitors to get in touch. So I offer the email address *and* a contact form, thus giving the visitor a choice.

                      To prevent spam, I’m not sure about how efficient this method of encoding addresses is in the long run is. A spambot could be programmed to find an encoded address as well. So I guess if an email address is public, you need to rely on some spam filtering anyway. I’m forwarding my mails to a gmail account, and they have a very effective spam filtering in place, with rarely any false positives. So I’m getting between 5 - 10 spam mails per week, which is no big deal to me. And occasionally I’m checking the spam folder.
                        René