Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

P.S.

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

$to = "example@email.com";      
$subject = "Mail Test at ".strftime("%T", time());      
$message = "This is a test."; 
$from = "Mike <mike@mysitename.com>";
$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)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

error_reporting(E_ALL);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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