I followed this tutorial to send emails from rails and it works just fine. But I want to improve this for my application. I don’t really want to receive emails from myself all the time, if someone were to use the contact us page. Currently I have the mail settings set as my own email and sent to my own email. My question is, is there a way to set it up such that the mail I receive from the email sent through the contact us page is the email they put in in the form?
To clarify, for example in a standard contact us page, there is the name, email, subject, body. Right now when I route the mail to myself, the :from and :to parameter are my own email, is there a way to set the :from parameter of the mail to the email specified on the page? I have tried changing mail(:subject => “[YourWebsite.tld] #{message.subject}”) to mail(:from => “#{message.from}”, :subject => “[YourWebsite.tld] #{message.subject}”) but that didn’t seem to work, I’m not really sure what to google for this specific problem because most of the contact us page tutorials I have come up with are similar to the one I already tried, which is more specific for sending mail to others instead of receiving.
Thanks!
You should not attempt to change the from field; most mail servers will not let you for obvious reasons. What you should be able to do is add a reply-to header with the email given in the address box (though often this will be bogus, esp on spam). Be very careful of course to validate your input.
Incidentally I’d set up a separate email user for your server to send from, to avoid issues with using your own email account. So use: