MidRo Posted August 12, 2014 Share Posted August 12, 2014 Hey! I've been tackling the code Ryan submitted for his simple contact form and I pretty much got it working, however, I was just wondering what you would recommend for spam filtering. Is just having a hidden field in the form something that you normally use for this? Or is there something more advanced you would recommend? Link to comment Share on other sites More sharing options...
kongondo Posted August 20, 2014 Share Posted August 20, 2014 Hi MidRo, Welcome to ProcessWire and the forums. I see your question has not been answered 7 days later! Apologies, we are normally not that slow RE spam, yes, a number of us (including Ryan) recommend using a 'honeypot' field to filter out spam. Read more here: https://processwire.com/talk/topic/960-comment-spam-filtering-alternatives/ 3 Link to comment Share on other sites More sharing options...
tuxy Posted February 23, 2015 Share Posted February 23, 2015 Hello, Thanks for this nice and simple contactform. It works very well For Anti Spam adding a input-field with a sum: 2+2 = ? But how can I adding the field in an if-condition? I made this on an other site in php-code, and works good: ... if (($_POST['human'] == '4')) ... PW is new for me and don't now how implement this with the API-field. <?php // Mailform $sent = false; $error = ''; $emailTo = 'myname@gmail.com'; // or pull from PW page field // sanitize form values or create empty $form = array( 'fullname' => $sanitizer->text($input->post->fullname), 'email' => $sanitizer->email($input->post->email), 'comments' => $sanitizer->textarea($input->post->comments), ); // check if the form was submitted if($input->post->submit) { // determine if any fields were ommitted or didn't validate foreach($form as $key => $value) { if(empty($value)) $error = "<div class='alert alert-danger' role='alert'>Please check that you have completed all fields.</div>"; } // if no errors, email the form results if(!$error) { $msg = "Naam: $form[fullname]\n" . "Email: $form[email]\n" . "Comments: $form[comments]"; mail($emailTo, "Contact Form", $msg, "From: $form[email]"); // populate body with success message, or pull it from another PW field echo "<div class='alert alert-success' role='alert'>Dank je wel, uw emailbericht is verstuurd.</div>"; $sent = true; } } if(!$sent) { // sanitize values for placement in markup foreach($form as $key => $value) { $form[$key] = htmlentities($value, ENT_QUOTES, "UTF-8"); } // append form to body copy echo <<< _OUT $error <form action="./" method="post"> <div class="form-group"> <label>Naam</label> <input type="text" class="form-control" id="fullname" name="fullname" value="$form[fullname]" /> </div> <div class="form-group"> <label>Email</label> <input type="email" class="form-control" name="email" id="email" value="$form[email]" /> </div> <div class="form-group"> <label>Comments</label> <textarea rows="5" id="comments" class="form-control" name="comments">$form[comments]</textarea> </div> <!-- Anti Spam --> <div class="form-group"> <label>Hoeveel is 2+2 (Anti Spam!)</label> <input type="text" class="form-control" name="human" placeholder="?" id="human" > </div> <div class="form-group"> <button type="submit" name="submit" value="Submit" class="btn btn-default">Verstuur</button> </div> </form> _OUT; }; ?> Regards, Christophe Link to comment Share on other sites More sharing options...
derelektrischemoench Posted June 25, 2015 Share Posted June 25, 2015 Hi guys, thanks for the great tutorial, however, I get zero output. Which is unfortunate. I'm new to this whole thing and my php-skills are poor, but could this have to do something with the last line of the file, the template-include? // include site's main template which outputs everything include("./home.php"); It would be awesome if anyone could help me with this. By the way, what would be my main template? I thought there was no such thing, the only thing that's consistent in my pages are the includes of the header and footer. /edit: I managed to do the redirect etc., after the mail is sent my code displays a success message, unfortunately though, it doesn't send a mail. I've tried several of my email adresses as recipients, it just doesn't work. Checked my spam folders as well, no luck there. I'm developing locally on a WAMP stack, could this have something to do with that perhaps something about the configuration of my apache server? /edit2: when I inspect the output of the site I get the following line: <form action="./" method="post"> Do I need to specify a designated mail option in a separate php- script? or does the one Ryan posted already do its job? Best regards, Chris Link to comment Share on other sites More sharing options...
tires Posted July 9, 2015 Share Posted July 9, 2015 I read about problems with blacklistings of sharedhosting servers. Mails sendig via php mail function end up in the spam folder. To avoid this i want to use smtp to send the mails. What would be the easiest way to set up an smpt-mail-form? Thanks and regards. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 9, 2015 Share Posted July 9, 2015 Use wireMail, the processwire mail class, and install the wiremailsmtp or swiftmailer module to let it use smtp instead of php mail. There are lot's of other topics (e.g. the modules support topics) around, where you can find written out examples on how to use wiremail and the module specific api's. Link to comment Share on other sites More sharing options...
tires Posted July 9, 2015 Share Posted July 9, 2015 Thanks for your answer! Ok, i installed the module "Wire Mail SMTP" and fill in the smtp data. My template contains the following code to submit the mail: $numSent = wireMail($emailTo, "Webmail", $msg, "From: $form[email]"); Is that the right way?The mail didn't reached me. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 9, 2015 Share Posted July 9, 2015 Did you read the api docs here: https://processwire.com/talk/topic/5704-wiremailsmtp/? Your arguments seem out of order. Also there's a option to test the modules configuration in the modules settings. Link to comment Share on other sites More sharing options...
tires Posted July 10, 2015 Share Posted July 10, 2015 Thanks for your answer! I checked the api docs and also tested the module configuration. In the api docs the following code is given: $numSent = wireMail($to, $from, $subject, $textBody); Is that right? Or do just have to write "wireMail(....);"? I think the arguments are ok (it works with the common php mail): $emailTo, "Webmail", $msg, "From: $form[email]" Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 10, 2015 Share Posted July 10, 2015 Why do you think your arguments are right? I translated your fields to the variables used by the docs. You need to change the order to make it work. // API Docs wireMail($to, $from, $subject, $textBody); // Your code wireMail($to, $subject, $textBody, $headers); … (it works with the common php mail): While wireMail is using php mail as default sending mechanism it's not a plain replacement method. Link to comment Share on other sites More sharing options...
tires Posted July 20, 2015 Share Posted July 20, 2015 You are absolutely right! This code works! $numSent = wireMail($emailTo, $form, "Formmail", $msg); Thanks and best regards! Link to comment Share on other sites More sharing options...
giannisok Posted September 6, 2016 Share Posted September 6, 2016 Check my post here: 1 Link to comment Share on other sites More sharing options...
howsoonisnow90 Posted November 23, 2021 Share Posted November 23, 2021 On 1/11/2012 at 5:02 PM, ryan said: You'll probably need to change these lines to be consistent with the approach you are taking with your templates: $page->body .= <<< _OUT That line assumes that you want to append the form to the 'body' field, and that it hasn't already been output. If you are using head/foot includes (like in the default profile), then you'll probably just want to echo the output, i.e. echo <<< _OUT Likewise, you'd want to change any other instances that append to $page->body, and instead echo that output (or assign it to another variable). The bottom of the example says this: include("./main.php"); It has that because it's assuming main.php handles all the output (rather than a head/foot include). So you may want to remove that line. thanks a lot, I've tried to paste this code but then I receive error 403, as when I press submit button it brings me here: mywebsite.com/site/assets/img/ how can I fix this? massive thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now