저는 Sinatra Jump Start의 연락 양식을 작성 중이며 "보낸 사람"이 항상 : user_name과 같은 gmail 계정 인 이유를 알아 내려고 노력하고 있습니다. 나는 Heroku 버전을 가지고 있으며 항상 동일합니다 :from
. 내 목표는 이름, 이메일 및 메시지가 수신 전자 메일로 전송되는 "작은"연락처 양식을 갖는 것이며 "보낸 사람"은 보낸 사람의 이름 및 전자 메일이됩니다.포니와 Sinatra는 항상 다음과 같은 이메일을 가지고 있습니다.
아마 로컬 버전 때문일 수도 있지만 Heroku와 같은 결과입니다. :user_name
에 대한 설정은 "보낸 사람"으로 끝납니다. 저는 잘못된 생각을하고 있습니까?
더 이상 정확하지 않은 :from => params[:name] + "<" + params[:email] + ">"
은 내가 사용하고있는 책이 너무 오래되었습니다.
p You can contact me by filling in the form below:
form class="contact" action="/contact" method="POST"
p
label for="name" Name:
input type="text" name="name"
p
label for="email" Email:
input type="text" name="email"
p
label for="message" Your Message:
textarea name="message"
input type="submit" value="Send Message"
내 send_message
입니다 : 내 main.rb
post '/contact' do
send_message
flash[:notice] = "Thank you for your message. We'll be in touch soon."
redirect to("/")
end
에서
def send_message
Pony.mail(
# this always comes back as the same gmail.account I'm using for the :user_name
:from => params[:name] + "<" + params[:email] + ">",
:to => '[email protected]',
:subject => params[:name] + " from #{params[:email]} has contacted you ",
:body => params[:message],
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => '[email protected]',
:password => 'mypassword',
:authentication => 'plain',
:domain => 'localhost.localdomain'
})
end
그리고 내 게시물 노선 핸들러 I가 시도 할 때 다음
여기처럼 내 contact.slim
형태의 모습입니다 헤로 쿠 나는 이것들을 가지고있다. main.rb
:
configure :development do
# for the local MySQL db
DataMapper.setup(:default, 'mysql://root:[email protected]/sinatra_jumpstart')
set :email_address => 'smtp.gmail.com',
:email_user_name => '[email protected]',
:email_password => 'mypassword',
:email_domain => 'localhost.localdomain'
end
configure :production do
# for Heroku
DataMapper.setup(:default, ENV[ 'DATABASE_URL' ])
set :email_address => 'smtp.sendgrid.net',
:email_user_name => ENV['SENDGRID_USERNAME'],
:email_password => ENV['SENDGRID_PASSWORD'],
:email_domain => 'heroku.com'
end
업데이트 : 내 목표는 회신에, 나는이에 params[:email]
를 전달할 수있는 :reply_to
옵션이있을 수있을 것입니다하지만 여전히 잎 경우 나 궁금 것 같다 왜 '에서'쇼 ('params[:name]
에서 오는) 이름을 올바르게 입력했지만'보낸 사람 '전자 메일 주소의 경우 params[:email]
을 무시하고 대신 :via_options
에서 내 :user_name
전자 메일을 표시합니다.