3

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)

0
3

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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