Skip to content

Instantly share code, notes, and snippets.

@andrellima
Created March 27, 2011 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrellima/889447 to your computer and use it in GitHub Desktop.
Save andrellima/889447 to your computer and use it in GitHub Desktop.
ActionMailer::Base.smtp_settings = {
:tls => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "localhost",
:user_name => "user",
:password => "***",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
class PublicController < ApplicationController
def contact
render :partial => 'formulario_contato'
end
def send_contact
nome = params[:contato]['nome']
fone = params[:contato]['telefone']
email = params[:contato]['email']
assunto = params[:contato]['assunto']
corpo = params[:contato]['corpo']
UserMailer.contact(nome, fone, email, assunto, corpo).deliver
render :text => '<h1> Formulário enviado com sucesso </h1>'
end
def cadastro_franquia
render :partial => 'formulario_franquias'
end
def send_cadastro_franquia
email = params[:franquia_cadastro]['email']
sexo = params[:franquia_cadastro]['sexo']
nome = params[:franquia_cadastro]['nome']
nascimento = params[:franquia_cadastro]['nascimento']
telefone = params[:franquia_cadastro]['telefone']
celular = params[:franquia_cadastro]['celular']
outro_telefone = params[:franquia_cadastro]['outro_telefone']
endereco = params[:franquia_cadastro]['endereco']
pais = params[:franquia_cadastro]['pais']
uf = params[:franquia_cadastro]['uf']
cidade_de_interesse = params[:franquia_cadastro]['cidade_de_interesse']
capital_de_investimento = params[:franquia_cadastro]['capital_de_investimento']
mensagem = params[:franquia_cadastro]['mensagem']
UserMailer.franquia(email, sexo, nome, nascimento, telefone, celular, outro_telefone, endereco, pais, uf, cidade_de_interesse, capital_de_investimento, mensagem).deliver
render :text => '<h1> Formulário enviado com sucesso </h1>'
end
def contact_sent
render :text => '<h1> Formulário enviado com sucesso </h1>'
end
end
class UserMailer < ActionMailer::Base
default :from => "from@example.com"
def contact(nome, fone, email, assunto, corpo)
from "SITE: COURO E CIA"
subject assunto
sent_on Time.now
content_type "text/html"
@nome = nome
@email = email
@fone = fone
@corpo = corpo
mail(:to => "azdr3milao@gmail.com", :subject => "Contato", :template_name => 'entrar_em_contato.html.erb')
end
def franquia(email, sexo, nome, nascimento, telefone, celular, outro_telefone, endereco, pais, uf, cidade_de_interesse, capital_de_investimento, mensagem)
from "SITE: COURO E CIA"
subject 'CADASTRO DE FRANQUIAS'
sent_on Time.now
content_type "text/html"
@email = email
@sexo = sexo
@nome = nome
@nascimento = nascimento
@telefone = telefone
@celular = celular
@outro_telefone = outro_telefone
@endereco = endereco
@pais = pais
@uf = uf
@cidade_de_interesse = cidade_de_interesse
@capital_de_investimento = capital_de_investimento
@mensagem = mensagem
mail(:to => "azdr3milao@gmail.com", :subject => "Contato para franquia", :template_name => 'cadastro_franquia.html.erb')
end
end
<form action="" method="get">
<div class="item_form" style="width:480px;">
Nome:<br />
<input name="contato[nome]" type="text" style="width:480px;"/>
</div>
<div class="item_form" style="width:480px;">
Email:<br />
<input name="contato[email]" type="text" style="width:480px;"/>
</div>
<div class="item_form" style="width:480px;">
Telefone:<br />
<input name="contato[telefone]" type="text" style="width:480px;"/>
</div>
<div class="item_form" style="width:480px;">
Assunto:<br />
<input name="contato[assunto]" type="text" style="width:480px;"/>
</div>
<div class="item_form" style="width:480px;">
Mensagem:
<textarea style="width:480px; height: 100px;" name="contato[corpo]"></textarea>
</div>
<%= submit_to_remote 'send', 'Enviar', :url => { :action => 'send_contact' },
:before => "$('load_form_contato').show();",
:update => { :success => "ajax_form_contato", :failure => "fail" }, :html => {:class => 'btn'} %>
<%= submit_to_remote 'clear', 'Limpar', :url => { :action => 'contact' },
:before => "$('load_form_contato').show();",
:update => { :success => "ajax_form_contato", :failure => "fail" }, :html => {:class => 'btn', :style => 'padding-left: 10px;'} %>
</form>
<div style="position: absolute; margin-left: 550px; margin-top: -200px; display: none;" id="load_form_contato">
</div>
O Sr(a) <b><%= @nome %></b> entrou em contato pelo site:
<br /><br />
Telefone de contato: <%= @fone %>
<br /><br />
E-Mail de contato: <%= @email %>
<br /><br />
Mensagem: <br /><%= @corpo %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment