-2

Everything was working ok until i added HTML. This code is sending the Email with an address as my hosting account username not the email i'm specifying.

$from = "info@site.com";
$headers = "From:" . $from. "\r\n";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to,$subject,$message,$headers);

After sending, the email is from some weird User@gdfgdfhgfdf bla bla intead of 'info@site.com';

and i assume it's my headers.

Thanks.

user3109875
  • 828
  • 12
  • 35
  • possible duplicate of [problem with php mail 'From' header](http://stackoverflow.com/questions/2014081/problem-with-php-mail-from-header) – putvande Jan 15 '14 at 10:58

2 Answers2

1

You're overwriting your headers, by using the = sign twice in a row, the second line should be

$headers  .= 'MIME-Version: 1.0' . "\r\n";
0

Try including your $from inside the $headers like this.

$from = "info@site.com";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: InfoSite <'.$from.'>'."\r\n"; //<--- Like this.
mail($to,$subject,$message,$headers);
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126