hungerstar
hungerstar

Reputation: 21685

correct email FROM header usage

I want to let users share information on my site by sending an email to a friend. Before I go to far I want to make sure I won't get blacklisted for doing something incorrectly.

If my domain is example.com can I set the mail FROM header to the email address supplied by the user?

For example, I want to share a page at example.com with my friend Bob. Bob's email address is [email protected] and my email address is [email protected]. When example.com sends an email to Bob([email protected]) it will set FROM to my email([email protected]).

Is this an issue since the email is being sent from example.com but the FROM header contains a domain other than itself?

The following would be sending from example.com

$to = '[email protected]';
$subject = 'Some subject';
$msg = 'Some message';
$headers = 'From: [email protected] <[email protected]>' . "\n\r";

mail( $to, $subject, $msg, $headers );

Or do I need to do something like the following?

$headers = 'From: [email protected] <[email protected]>' . "\n\r";

Any and all help will be greatly appreciated.

Upvotes: 1

Views: 1127

Answers (4)

ldg
ldg

Reputation: 9402

Many, if not most, email servers are not registered for a specific domain, the bigger issue is if your server correctly identifies itself (having a reverse lookup entry can help) and make sure it's not blacklisted. You can use a service like: http://www.dnsbl.info/ to check.

Most hosts with dynamic IPs are considered suspect, but even a dedicated VPS can be listed, so it's worth checking. You should also correctly format the headers as outlined in some of the other responses. If this is for a critical application (e.g., you are charging people and they expect to get mail), you should consider a 3rd-party SMTP which should take care of making sure you don't get blacklisted.

Upvotes: 0

RHSeeger
RHSeeger

Reputation: 16262

There are multiple email headers that give some indication of who "sent" an email and who to reply to. A fairly good, casual writeup of the concept can be found on the page discussing how FormMail handles things.

In general, the Sender is the actual originator of the email message. The From Address, in contrast, is simply a header line in the email that may or may not be taken to mean anything. The From Address can often be left out completely. Spammers can easily spoof the From Address. ISPs try to ensure that spammers cannot spoof the Sender.

It sounds like what you might want is:

  • Sender : your site/program
  • From : either your site or the user
  • Reply-To : the user

Upvotes: 1

Gryphius
Gryphius

Reputation: 78886

What you write in the from header isn't that relevant. Important is that you you use an envelope sender address from your domain. This is checked against SPF for example. If you want the recipient to be able to reply to [email protected] you need to add a reply-to header as well.

Upvotes: 1

genesis
genesis

Reputation: 50976

No, it really DOESN't matter which From: header email has been set

Why didn't you try it?

Upvotes: 0

Related Questions