I'm trying to work with sending mail through PHP for the first time and I've done pretty well with the exception of one thing. All mail i send is from an email address that ends in "justhost.com" (justhost is hosting my site). I was wondering is anyone could help me change this to a different email address.


Here is the php I'm using to send things from:

$to = "[email protected]";      
$subject = "Mail Test at ".strftime("%T", time());      
$message = "This is a test."; 
$from = "Mike <[email protected]>";
$headers = "From: {$from}\r\n";
$result = mail($to, $subject, $message, $header); 
echo $result ? 'Sent' : 'Error';

(sorry about the spacing I'm not sure how to fix it)


1 Answer 1


You're missing the "s" in $header in the mail() function:

$result = mail($to, $subject, $message, $header); 

should be

$result = mail($to, $subject, $message, $headers); 

Without a proper From header set you'll get the default from address for the server. Correcting this syntax error will solve that problem.

FYI, always develop with error reporting set to show all errors including notices. If you had done this you would spotted this error quickly.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.