ユーザーが送信をクリックするとメールが送信され、受信トレイに受信される連絡先フォームを作成できました。私はその電子メールをsendgrid経由で送信して分析を分析できるようにしたいと思います。私はGorails Sendgridコースを見て、sendgrid経由でメールを送ることができましたが、私はそれを私の連絡フォームにどのように適用するのか分かりません。私は下の私のコードを記載している、どんな助けも素晴らしいだろう。どうもありがとうございます! (ユーザーがクリックを提出したときに定期的に電子メールを送信しますお問い合わせフォーム)RailsメールフォームとSendgridをリンクするには?
new.html.erb
<div align="center">
<h3>Send A message to Us</h3>
<%= form_for @contact do |f| %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name, :required => true %>
</div>
<div class="field">
<%= f.label :email %><br>
<%= f.email_field :email, :required => true %>
</div>
<div class="field">
<%= f.label :message %><br>
<%= f.text_area :message, :as => :text, :required => true %>
</div>
<div class="actions">
<%= f.submit "Send Message", :class => "btn btn-primary btn-md"%>
</div>
<% end %>
</div>
contacts_controller.rb
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
@contact.request = request
if @contact.deliver
flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :message)
end
end
Sendgrid.rb(内私の設定>イニシャライザフォルダ)
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => Rails.application.secrets.sendgrid_api_key,
:domain => 'tango.co',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
development.rb
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:user_name => 'apikey',
:password => Rails.application.secrets.sendgrid_api_key,
:domain => 'tango.co',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}
メーラーのフォルダ私はこのために欠けていたものを考え出し