I have a simple contact form on a site.
There is an email account just to handle the mail being sent through the contact form. This is 'mycompany.noreply@gmail.com'
The problem
When a user fills in the form and sends it, two emails are sent. One confirmation email to the user of the site and the actual filled in form to the company.
The company wants it so when they receive the email from the user, they hit reply and the users email address is automatically in the 'to' field. But when they do that at the moment, what they see is "Senders name 'mycompany.noreply@gmail.com'" instead of "Senders name 'sender_email_address'".
The code
class Notifications < ActionMailer::Base
def enquiry(user)
@user = user
mail(to: "employee@mycompany.com", subject: "website enquiry", from: "#{@user.name} <#{@user.email}>")
end
def no_reply(user)
@user = user
mail(to: @user.email, from: "My Company <mycompany.noreply@gmail.com>", subject: "Message received at mycompany.com")
end
end
Tests
The test for the from field passes.
require "spec_helper"
describe Notifications do
let(:contact_form) { FactoryGirl.build(:contact_form) }
context "enquiry" do
let(:mail) { Notifications.enquiry(contact_form) }
it "renders the headers" do
mail.from.should eq([contact_form.email])
end
end
end
Also, I am using mailcatcher.
Mailcatcher also shows the correct user.email
in the from field.
It only seems to be when the actual email is received (using gmail) that the wrong address appears.
Any help appreciated.
EDIT
Default mail settings:
# mail config settings
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => 'mycompany.noreply@gmail.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
mail header from mailcatcher
Date: Sat, 13 Oct 2012 21:08:02 +0100
From: Joe Bloggs <joebloggs@gmail.com>
To: mycomany.noreply@gamil.com
Message-ID: <5079ca229969b_67c23fc061434ed023056@Mark-Charless-iMac-2.local.mail>
Subject: website enquiry
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5079ca226fb17_67c23fc061434ed02277b";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5079ca226fb17_67c23fc061434ed02277b
Date: Sat, 13 Oct 2012 21:08:02 +0100
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <5079ca227ec80_67c23fc061434ed02288a@Mark-Charless-iMac-2.local.mail>