tags:

views:

149

answers:

5
$to = "[email protected]";
$subject = "Auction Registration Confirmation";
$from = "From: [email protected]";
$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.

A: 

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
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 [email protected]
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
Could you provide me with a solution
A: 

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
whats the solution?
@pete the solution is to use a different MTA, or edit your MTA settings.
Unknown
@unknown, Right I know I have edit the MTA Settings, but what and how?
A: 

did you try this? it works for me fine

<?php
$to = "[email protected]";
$subject = "subject";
$message = "message";
$from = "[email protected]";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
CheeseConQueso
A: 

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