我不确定如何解决这个问题 - 我们非常感谢任何帮助。
当客户填写联系表单时,我想知道如何使用ActionMailer向admin(akunorbea@gmail.com)和客户端(client@gmail.com)发送电子邮件。
我的终端显示电子邮件正在发送给管理员(akunorbea@gmail.com)&客户端(client@gmail.com)
模式
create_table "contacts", force: true do |t|
t.integer "category_department_id"
t.string "firstname"
t.string "lastname"
t.string "companyname"
t.string "email"
t.integer "number"
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
t.integer "category_enquiry_id"
t.string "tel"
end
contacts_controller.rb
class ContactsController < ApplicationController
respond_to :html, :xml, :json
before_action :set_contact, only: [:show, :edit, :update, :destroy]
def create
@contact = Contact.new(contact_params)
respond_to do |format|
if @contact.save
MailerContact.contact_us(@contact).deliver
MailerContact.contact_us_confirmation(@contact).deliver
format.html { redirect_to message_sent_path, :notice => 'message sent' }
format.xml { render :xml => @contact, :status => :created, :location => [@contact] }
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
end
end
mailer_contact.rb
class MailerContact < ActionMailer::Base
def contact_us(contact)
@contact = contact
mail( to: "akunorbea@gmail.com",
subject: "Client Enquiries",
from: "#{contact.firstname} <#{contact.email}>")
end
def contact_us_confirmation(contact)
@contact = contact
mail( to: "#{contact.firstname} <#{contact.email}>",
subject: "Thank you for your Enquiries",
from: "<no-reply@africanjober.com>")
end
end
html.erb文件
contact_us.html.erb
This email goes to the admin (akunorbea@gmail.com)
"displays Client enquiries"
contact_us_confirmation.html.erb
This email goes to the client (client@gmail.com)
"Thank you for your enquiries"
答案 0 :(得分:0)
动作邮件程序一次只发送一封电子邮件。不是为了在同一个控制器中同时发送2封电子邮件而构建的