Reputation: 2097
When a user sends some enquiry through a company's website, he also enters email,
now is there a way where the email when received to the enquiry department will reflect as :
From : [email protected]
to : [email protected]
Subject: enquiry
Some Text
where "[email protected]" is the email entered by user in the enquiry form.
the same can be seen in some e-card website, where you send ecard to your friends email and they receive it with your address in the "from" part.
how can this be achieved?
------------EDIT-------------
Example:
Front-End :
To send ecard to your friend: your email address : [email protected] your friends email address: [email protected]
and then friend receives an email as:
from: [email protected] via jkh.hk.dn.net
to: [email protected]
subject: ecard
ecard email
as you can see though the email is send the e-card website, the from address reflect the email address entered by user.
So need some help on how this can be achieved? and any example would be more helpful...
Upvotes: 2
Views: 516
Reputation: 26956
You might have more success using the "reply-to" and "sender" fields, which can be different to the from address, and most mail clients should honour - and has less "spammy" connotations:
So your form has:
From address: [email protected]
To address: [email protected]
Then when you generate the email you send it as:
from: [email protected] // Your domain name, that is allowed to send emails
to: [email protected]
reply-to: [email protected]
This way the receiving mail server can see you're being honest about where the email is coming from, and if they check any SPF records for the from
domain they should match with your server. However when the user hits "Reply" the email should go to the Reply-to address instead.
If you really want to set the user's email as the from
field then you should set the system email address as the sender
:
from: [email protected]
sender: [email protected]
to: [email protected]
reply-to: [email protected]
This will result in the email appearing as "From [email protected] on behalf of [email protected]".
See also the following Stack Overflow question:
Should I use the Reply-To header when sending emails as a service to others?
Upvotes: 2
Reputation: 8461
Yes you can do this, but it depends on what rights your mail server has. When I manage servers, I ensure this option is disabled. You will need to talk to whoever managers your SMTP server; However, as a web developer I know why you want it but I strongly advise against.
What you are proposing is very dangerous as you're sending email via someone's domain without their permission. This then means technically, I can come to your website and fill in any message and any email addresses and 'SPAM' via your service.
You are better to have the email set as
From name@Mycompay
To customer@hisDomain
BCC name@MYCompany
Upvotes: 1