PHP mail() how to set sender mail

email, php

Solution

Try setting the envelope sender, as well setting the sender in the headers of the message, like so:

$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);   

Problem

This is my code: ``` $to = 'to@mail.com'; $subject = 'test'; $body = 'test'; $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header .= "To: <$to>" . "\r\n"; $header .= 'From: from@mail.com \r\n'; mail($to, $subject, $body, $header); ``` The code works, it sends the email. But the sender is not the one that I defined. The sender seems to be the webmail host. What am I doing wrong?

Original source