Question

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 : user@xyz.com

to : enquiry@myCompany.com

Subject: enquiry

Some Text

where "user@xyz.com" 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 : abc@xyz.com your friends email address: lmn@pqr.com

and then friend receives an email as:

from: abc@xyz.com via jkh.hk.dn.net
to: lmn@pqr.com
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...

Was it helpful?

Solution

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: user@abc.com
To address: friend@xyz.com

Then when you generate the email you send it as:

from: website@example.com // Your domain name, that is allowed to send emails
to: friend@xyz.com
reply-to: user@abc.com

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: user@abc.com
sender: website@example.com
to: friend@xyz.com
reply-to: user@abc.com

This will result in the email appearing as "From website@example.com on behalf of user@abc.com".

See also the following Stack Overflow question:

Should I use the Reply-To header when sending emails as a service to others?

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top