I can send mail from my site fine using Sinatra and Pony mail.The problem lies in setting the body to use an erb template.
So my config is set like so
post '/' do
from = params[:name]
subject = "#{params[:name]} has contacted you"
body = erb(:mail)
Pony.mail(
:from => from,
:to => ENV["EMAIL_ADDRESS"],
:subject => subject,
:body => body,
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => '587',
:enable_starttls_auto => true,
:user_name => ENV["USER_NAME"],
:password => ENV["PASSWORD"],
:authentication => :plain,
:domain => "localhost.localdomain"
})
flash[:notice] = "Thanks for your email. I will be in touch soon."
redirect '/success'
So my subject renders correclty, but the body of the message is actually returned as the html source for my webpage (as if i had right clicked view source)
My erb template is like so
Hello Rich,
Seems as if you have recieved an email from <%= params[:name] %> via your website.
Their email address is <%= params[:email] %>, this is what they said.
<%= params[:message] %>
So why isnt the body rendering the erb tempalte?
Im a bit confused here? Have i set something up incorrectly within the erb template?
Thanks
Ok so for anyone else with same issue what i needed to do was tell sinatra not to use my layout file, so when setting
body = erb(:mail)
It needed to be
body = erb(:mail, layout: false )