Created
November 26, 2011 21:40
-
-
Save flores/1396337 to your computer and use it in GitHub Desktop.
Sinatra + Sanitize + AWS SES Contact form, example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%form{ :action => "/", :method => "post"} | |
%label{:for => "name"} name: | |
%input{:type => "text", :name => "name""} | |
%label{:for => "mail"} email: | |
%input{:type => "text", :name => "mail"} | |
%label{:for => "subject"} subject: | |
%input{:type => "text", :name => "subject"} | |
%label{:for => "body"} message: | |
%textarea{:name => "body"} | |
%input{:type => "submit", :value => "send", :value => "send"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -r openssl | |
require 'rubygems' | |
require 'sinatra' | |
require 'haml' | |
require 'sanitize' | |
require 'aws/ses' | |
set :environment, :production | |
set :port, '4000' | |
set :bind, 'localhost' | |
get '/' do | |
haml :contact | |
end | |
post '/' do | |
name = Sanitize.clean(params[:name]) | |
mail = Sanitize.clean(params[:mail]) | |
subject = Sanitize.clean(params[:subject]) | |
body = Sanitize.clean(params[:body]) | |
ses = AWS::SES::Base.new( | |
:access_key_id => 'someid', | |
:secret_access_key => 'somekey' | |
) | |
# stick the user info into the subject instead of headers | |
ses.send_email( | |
:to => 'someemail', | |
:from => 'somefilteredemail', | |
:subject => mail + " - " + name + " - " + subject, | |
:body => body | |
) | |
haml :success | |
end | |
error do | |
haml :error | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment