0
$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.

Paul Dixon
  • 295,876
  • 54
  • 310
  • 348

4 Answers4

1

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
0

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.";
?> 
CheeseConQueso
  • 5,831
  • 29
  • 93
  • 126
0

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?

RichieHindle
  • 272,464
  • 47
  • 358
  • 399
  • assume the server, where all administration is done, the login name is "admin". The code is fine, but the problem is that when the email is sent it will show the from address as "admin" and not do-not-reply@mydomain.com –  May 17 '09 at 07:02
  • Yes, I understand the question. 8-) When I say "my similar code works fine" I mean that I'm passing a "From:" line to the PHP mail() command just like you're doing, and the emails are arriving with the correct From header. – RichieHindle May 17 '09 at 07:06
  • Could you provide me with a solution –  May 17 '09 at 07:23
0

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.

Unknown
  • 45,913
  • 27
  • 138
  • 182