3

I'm trying to send mails with the name of the user in the from address. Something like "John Doe <john@doe.com>". I went through a lot of SO solutions, but still couldn't get this to work.

Here's the mailer:

def trigger_email(send_mail, contact, user)
    @mailer = send_mail
    @email = contact.email
    @user = User.find(user)
    mail(to: @email, subject: @mailer.subject, from: "\"#{@user.name}\" <@user.email>")
end

I have tried quite a few variants of the above but nothing works. Would appreciate a solution to this issue.

jasonng
  • 107
  • 1
  • 7

1 Answers1

2

The from: value in the mail() line seems to be wrong. Try:

mail(to: @email, subject: @mailer.subject, from: "#{@user.name} <#{@user.email}>")

If that does not work, check with your email provider, maybe they're altering that?

dgilperez
  • 10,716
  • 8
  • 68
  • 96