Search code examples
phpemailoutlookgmail

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 = "[email protected]";
$from = "[email protected]";
$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?


Solution

  • 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.