This question already has an answer here:
$to = "me@mydomain.com";
$subject = "Auction Registration Confirmation";
$from = "From: donot-reply@mydomain.com";
$body = "Test Message";
if (mail($to, $subject, $body, $from)) {
echo("<b>Message sent</b>");
header( "Location: http://www.mydomain.com/thankyou.html" );
} else {
echo("<b>Message failed</b>");
}
Now the problem is that when an email is sent, the from address is not what I require, but the server login name.
Any ideas as to replace the server login name with the from email id.
</div>
There doesn't look to be anything wrong with your PHP code - I have very similar code doing the same job and it works fine.
Possibly there's something misconfigured with your email setup?
The PHP mail function relies on the MTA running on your server. I would bet that your MTA is setup to force the $from variable to your login name.
did you try this? it works for me fine
<?php
$to = "email@to.com";
$subject = "subject";
$message = "message";
$from = "email@from.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
YOu could try
mail($to, $subject, $body, $from, "-f $from");
this works in some configurations, really depending on the server setup. Otherwise, edit your MTA settings as recommended above, or skip mail() altogether and use a class like PHPmailer that connects directly to the SMTP server.