0
mailform gem을 사용하여 레일 5 앱에 contact us 페이지를 만들려고합니다. https://www.youtube.com/watch?v=QIoORYeBdhs레일스 5 mailform not mail 메일 보내기
그러나 실제로 전자 메일을 개발 모드 또는 프로덕션 모드로 제공 할 수는 없지만 그 이유는 확실하지 않습니다. 어떤 도움을 많이 주시면 감사하겠습니다! 여기
내가 가진 무엇 :Welcome.rb :
class Welcome < MailForm::Base
attribute :name, :validate => true
attribute :email, :validate => /\A([\w+\-].?)[email protected][a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
attribute :message, :validate => true
attribute :nickname, :captcha => true
def headers
{
:subject => "Contact from About Site",
:to => "[email protected]",
:from => %("#{name}" <#{email}>)
}
end
end
welcome_controller :
class WelcomeController < ApplicationController
def index
@welcome = Welcome.new
end
def create
@welcome = Welcome.new(params[:welcome])
@welcome.request = request
if @welcome.deliver
flash.now[:error] = nil
else
flash.now[:error] = 'Cannot send message.'
render :index
end
end
end
양식 자체 (index.html.erb)
<section id="contact">
<div class="container">
<%= form_for welcome_index_path do |f| %>
<%= f.label :name %>
<%= f.text_field :name, required: true %>
<br>
<%= f.label :email %>
<%= f.email_field :email, required: true %>
<br>
<%= f.label :message %>
<%= f.text_area :message, as: :text %>
<div class="hidden">
<%= f.label :nickname %>
<%= f.text_field :nickname, hint: "Leave this field blank" %>
</div>
<br>
<%= f.submit 'Send Message', class: "btn btn-primary btn-large" %>
<% end %>
</div>
</section>
그리고 지금 내 설정 파일 :
이config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {:address => "localhost", :port => 1025}
모두 괜찮습니다. 'heroku addons : create sendgrid : starter'를 실행 했습니까? – boholdyjeramae
답변 해 주셔서 감사합니다. 나는 그랬다 - 실제로 그러나, 그것이 약 2 일 지연 후에, 일하기 시작했다고 보인다. 왜 그런지는 모르겠지만 지금은 작동 중입니다. 나는이 질문으로 돌아가 그것을 표시하는 것을 잊어 버렸습니다. 감사! –