Web Worm
Web Worm

Reputation: 2066

php mail() headers problem

here is my code....

$subject = "This is Subject";
$headers .= 'Content-type: text/html; charset=iso-8859-1';  
$to = '[email protected]';
$body = 'Mail Content Here';        
mail($to, $subject, $body, $headers);

but when i open this file it sends a mail to $to successfully but with wrong headers....and my hosting server default address i.e mars.myhosting.com, instead of [email protected] how can i fix that

Upvotes: 0

Views: 408

Answers (2)

Galen
Galen

Reputation: 30170

Look at this from php.net

$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: Webmaster <[email protected]>' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

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

Add the from header

Upvotes: 3

ninu
ninu

Reputation: 920

Here is what I would do via PHP:

<?PHP

$to = '[email protected]';
$subject = 'desired subject';
$message = 'desired message';
$headers = 'From: [email protected]' . "\r\n" .
   'Reply-To: [email protected]' . "\r\n" .
   'Return-Path: [email protected]' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

?>

I hope that helps some :)

Upvotes: 2

Related Questions