Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

headers in PHP mail function

Posted on 2011-02-12
5
Medium Priority
?
377 Views
Last Modified: 2012-05-11
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 >>>
0
Comment
Question by:MohammadAliQureshi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 2000 total points
ID: 34880792
If you send email out from a non-existent domain, most receiving servers will treat it as spam and your users/customers will never get it. It is common for a mail server to do a reverse lookup on the originating IP and see if the claimed domain is present there.

Other than that, the 'from' address is not set in the headers, but the 'Reply-to' address is set there. The 'from' is the first parameter in the mail() function.
0
 

Author Comment

by:MohammadAliQureshi
ID: 34880819
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 >>>
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 34880863
"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......  :-(

0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 34881026
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

0
 

Author Closing Comment

by:MohammadAliQureshi
ID: 34881155
I changed the from header to include a real email address and it is now working properly.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question