Mobile app version of vmapp.org
Login or Join
Karen161

: How do I change the default email that my host sends from php mail from in Justhost's C-panel I'm trying to work with sending mail through PHP for the first time and I've done pretty well

@Karen161

Posted in: #Email #Php #Server

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}rn";
$result = mail($to, $subject, $message, $header);
echo $result ? 'Sent' : 'Error';


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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Karen161

1 Comments

Sorted by latest first Latest Oldest Best

 

@Pope3001725

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme