简体   繁体   中英

how does PHP know the real email of the host or server?

As you know there are a lot of websites ( Just search on Google ) that will send fake email(!), and sending fake email is really easy (As you know).

PHP Example:

$to = "to@to.com";
$from = "from@from.com";
$subject = "subject";
$message = "this is the message body";

$headers = "From: $from"; 
$ok = @mail($to, $subject, $message, $headers, "-f " . $from);   

Is there anyway to set PHP with original server (domain) email, and How does Email service provider detect Email really sent from orginal domain or it is FAKE ?

In your dns account you need to set your MX record pointing to your domain name.

Regarding your second question.

When an email is recieved, it might have a fake from address but the ip address of the server that sent the mail cannot be fake. There are many organisation and services providers that keep on updating their database for every spam email server that get notice of. Email service providers either own that service or use some other services providers to filter the emails. One famous organisation being spamhaus .

I hope this helps you.

  1. Well you can check with getmxrr() if the domain in the e-mail address (so in your example from.com ) has a registered MX record in the DNS zone which will handle incoming and outgoing mails.
  2. In the header of the e-mail there is something like Received: from[ip-address] . You can check this against the MX record you got for the from.com domain. If there are more than one Received: from go with the last one .

In theory you can check with this process if the e-mail sent to you really has been sent by the server which is managing the mails for the given domain.

In theory because: a spamer could work around that (ex with a hacked e-mail account). But then the spam sent out by this e-mail account should be relatively small because the e-mail provider will detect the spamer and block the e-mail account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM