Contact Form with CAPTCHA Script


SUBMITTED BY: rajesh93

DATE: Feb. 16, 2017, 9:43 a.m.

FORMAT: Text only

SIZE: 856 Bytes

HITS: 710

  1. local USERNAME = '<SMTP USERNAME>'
  2. local PASSWORD = '<SMTP PASSWORD>'
  3. local SERVER = '<SMTP SERVER>'
  4. local RECAPTCHAKEY = '<RECAPTCHA PRIVATE KEY>'
  5. local recaptcha = require 'recaptcha'
  6. local markdown = require 'markdown'
  7. if recaptcha.validate(RECAPTCHAKEY, request) then
  8. html = markdown(request.form.body)
  9. email.send {
  10. server = SERVER, username = USERNAME, password = PASSWORD,
  11. from = 'hello@webscript.io', to = 'hello@webscript.io',
  12. subject = '[contact form] '..request.form.subject,
  13. text = request.form.body,
  14. replyto = request.form.replyto,
  15. html = html
  16. }
  17. return '<p>Sent the following mail:</p>'
  18. ..'<p>Subject: '..request.form.subject..'</p>'
  19. ..html,
  20. {['Content-Type'] = 'text/html'}
  21. else
  22. return 'Failed CAPTCHA.'
  23. end
  24. Demo Code

comments powered by Disqus