PHP mail () how to set sender mail

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 an email. But the sender is not the one I determined. The sender seems to be a web server. What am I doing wrong?

+7
php email
source share
1 answer

Try setting the sender of the envelope, and also set the sender in the message headers like this:

 $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); 
+19
source share

All Articles