I've spent time for research, and this is what I could think of.
But, I'm pretty sure there's something wrong with this part @users_emails += user.email
Can anyone fix my code to make it work?
controllers/users_controller.rb
def send_all_at_once
@notification_users = User.where("users.country_id=?", 36)
@notification_users.each do |user|
@users_emails += user.email
end
@subject = "Test subject"
@body = "Test body"
CallMailer.call_email(@users_emails, @subject, @body).deliver
end
app/mailers/call_mailer.rb
class CallMailer < ActionMailer::Base
default :from => "dont-reply@example.com"
def call_email(@users_emails, @subject, @body)
mail(:to => "admin@example.com",
:bcc => @users_emails,
:subject => @subject,
:body => @body) do |format|
format.html
format.text
end
end
end
views/call_mailer/call_email.html.erb
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>
You received a message.
</p>
<p>
Subject: <%= raw @subject %>
</p>
<blockquote>
<p>
<%= simple_format(@body) %>
</p>
</blockquote>
<p>
From: <%= link_to root_url,root_url %>
</p>
</body>
</html>