0
我試圖在本地發送郵件,但它不發送郵件。實際發生了什麼....?郵件不在本地發送ROR
位指示
class ForestsController < ApplicationController
before_action :set_forest, only: [:show, :edit, :update, :destroy]
# GET /forests
# GET /forests.json
def index
@forests = Forest.all
end
# GET /forests/1
# GET /forests/1.json
def show
end
# GET /forests/new
def new
@forest = Forest.new
end
# POST /forests
# POST /forests.json
def create
@forest = Forest.new(forest_params)
respond_to do |format|
if @forest.save
UserMailer.welcome_user(@forest).deliver
format.html { redirect_to @forest, notice: 'Your Message send successfully.' }
format.json { render action: 'show', status: :created, location: @forest }
else
format.html { render action: 'new' }
format.json { render json: @forest.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_forest
@forest = Forest.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def forest_params
params.require(:forest).permit(:name, :email, :phone, :body)
end
end
UserMailer
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def welcome_user(forest)
@forest = forest
mail(to: @forest.email, subject: "Hello Man", body: @forest.body)
end
end
查看
= form_for :forest, url:{:action =>"create"}, html:{:class => "form-horizontal" } do |f|
%div.form-group
= f.label :name, 'Name', {:class => 'col-lg-2 control-label'}
%div.col-lg-3
= f.text_field :name, {:class => 'form-control', :placeholder => "Your Name"}
%div.form-group
= f.label :email, 'Email', {:class => 'col-lg-2 control-label'}
%div.col-lg-3
= f.text_field :email, {:class => 'form-control', :placeholder => "[email protected]"}
%div.form-group
= f.label :phone, 'Phone', {:class => 'col-lg-2 control-label'}
%div.col-lg-3
= f.text_field :phone, {:class => 'form-control', :placeholder => "Mobile No"}
%div.form-group
= f.label :body, 'Body', {:class => 'col-lg-2 control-label'}
%div.col-lg-3
= f.text_area :body, {:class => 'form-control', :placeholder => "Your Message"}
%div.form-group
%div.col-lg-offset-2.col-lg-10
= f.submit :class => "btn btn-primary", :value => "Contact Us"
發生了什麼事......?爲什麼它不發送郵件...?我無法理解這個問題....任何關於這個的建議都會對我有所幫助......?
添加後,這些在developemnt.rb文件,我的服務器沒有啓動 – TayyabZahid
好了,也不好 - 做日誌文件說些什麼?順便說一句:代碼中的所有內容都應該用適當的值來代替,例如「CONFIG [...]」。 「user_name:'[email protected]'」或任何你的憑據是... – Ben
它只是取代配置與我的域名,用戶名和密碼....然後其工作.... – TayyabZahid