Rails联系表单 - 已发送电子邮件,但未在我的收件箱中收到

时间:2016-01-28 01:24:11

标签: ruby-on-rails ruby-on-rails-4

我是铁杆新手。我创建了一个应用程序和一个简单的联系表单。当我填写联系表格时,它似乎提交一切正常。我没有收到任何错误,控制台显示它有效。

但是我没有在收件箱或垃圾邮件文件夹中收到这些电子邮件。谁能告诉我我做错了什么?

我遵循了tutorial

路线

 match '/contacts',     to: 'contacts#new',             via: 'get'
  resources "contacts", only: [:new, :create]

通讯录控制器

class ContactsController < ApplicationController
  def new
    @contact = Contact.new
  end

  def create
    @contact = Contact.new(params[:contact])
    @contact.request = request
    if @contact.deliver
      redirect_to root_path
      flash.now[:notice] = 'Thank you for your message. We will contact you soon!'
    else
      flash.now[:error] = 'Cannot send message.'
      render :new
    end
  end
end

模型

class Contact < MailForm::Base
  attribute :name,      :validate => true
  attribute :email,     :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
  attribute :message
  attribute :nickname,  :captcha  => true

  # Declare the e-mail headers. It accepts anything the mail method
  # in ActionMailer accepts.
  def headers
    {
      :subject => "My Contact Form",
      :to => "myemail@gmail.com", 
      :from => %("#{name}" <#{email}>)
    }
  end
end

New.html.erb

<div align="center">
  <h3>Send A message to Us</h3>
  <%= simple_form_for @contact, :html => {:class => 'form-horizontal' } do |f| %>
    <%= f.input :name, :required => true %>
    <%= f.input :email, :required => true %>
    <%= f.input :message, :as => :text, :required => true %>
    <div class= "hidden">
      <%= f.input :nickname, :hint => 'Leave this field blank!' %>
    </div>
    <div>
      </br>
      <%= f.button :submit, 'Send message', :class=> "btn btn-primary" %>
    </div>
  <% end %>
</div>

Create.html.erb

<div>
  <% flash.each do |key, value| %>
    <div>
      <a href="#" data-dismiss="alert">×</a>
        <%= value %>
    </div>
  <% end %>
</div>

0 个答案:

没有答案