Link to home
Start Free TrialLog in
Avatar of MohammadAliQureshi
MohammadAliQureshi

asked on

headers in PHP mail function

Hello:

I  am using PHP mail function. All is going well except the "FROM: " is not giving the correct email address. The header information is coded as follows:

    $headers = "From: DONOTREPLY@mysite.org\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

By the way, the email is in HTML format.

What I get in the From field is "From: someid@myhostingdomain.com". What I want is "From: DONOTREPLY@mysite.com".
The idea is that the user will ask a question from the site and the answer is emailed to the user using PHP email. However, the userid used in from is supposed to be outgoing mailbox only. Since I do not know how to setup outgoing mailbox, what I am doing is using an email address that does not exist. In this case even if someone wants to reply to the email, they will get an error my their email system.

Thanks,
<<< Ali >>>
ASKER CERTIFIED SOLUTION
Avatar of Beverley Portlock
Beverley Portlock
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MohammadAliQureshi
MohammadAliQureshi

ASKER

Hello bportlock:
Thanks for the quick reply ...

The domain does exists, just the email is afake one. May be when server looksup the email address and does not find it, it treats as spam.

May be missed something, I think the TO is the first parameter in the mail() function, than subject, then message and then header.

May be I need to find out "How to setup outgoing only email address".

I will try to use a real email address in FROM and update you with the result.

Thanks,
<<< Ali >>>
"I think the TO is the first parameter in the mail() function,"

In PHP's mail() function - I was thinking of the PEAR HTML-mail class. Sorry......  :-(

Sometimes you have to put a 5th parameter specifying the From address to get it to work right.  Otherwise, the email address that is in 'php.ini' is used.
<?php
mail($to, $subject, $message, $headers, "-femail.address@example.com");
?>

Open in new window

I changed the from header to include a real email address and it is now working properly.