how does mail works
Image via Wikipedia

Most of us very well know about mail() provided by PHP which will help us send an email.Okay? Whats the point? Why is this blog? What’s new? Yeah, yeah, I will get to it straight. I am not going to say anything new here, but a little bit of information about how to avoid return-path problem in sending an email.

Recently I was working on a bug which took almost 4 hour for me crack and fix it. It was like this bug was telling:- can you fix me dude? Do you really think you can? I was like going mad and said yes you dirty-bug I am gonna fix you soon.

The problem was mail() function was delivering the email to all of the TO, CC, & BCC to all the people in the list except the client people’s address – this is blocker, the people who suppose to receive this email were not getting it. Wow isn’t.

I was like going mad, I could receive my email to my official ID, gmail ID, yahoo ID, etc and I also checked the IP of the email server is not in any of the blacklisted softwares.

I started reaching the usual path, checking out the logs (mail, queue, etc), then I noticed the root user was getting a mail reporting that the local apache user is not a proper email ID and hence our client mail-server was rejecting any mail coming from this user.

This is funny, because the “From” address was a correct email address but I saw the error with local apache user how come? I was surprised, then I went back to the theory and took a deep dive into the mail headers, there you go, I found the problem, the reply-to/return-path was going as a local apache user. In our server the mail configuration was not set to take the “From” email address by default if “reply-to” or “return-path” is not specified.


Having the valid email address to “reply-to” and “return-path” solves this problem. For ex:

$headers = ‘From:’ . “\r\n” .
‘Reply-To:’ . “\r\n” .
Return-Path:’ . “\r\n” .


Most of the server mail configuration will be setup in a way to take the “From” email by default. Makesure you confirm this or else make sure when you send an email do update the valid email address to “reply-to” & “return-path” type.

Have a happy mailing! ;-).

Reference for detail:




5 thoughts on “PHP MAIL Header – REPLY-TO and RETURN-PATH

  1. Amol Patil says:

    This is very Good Concept and most important it’s in very simple technical language.

    i have problem in inbox delivery in yahoo. Whenever I am changing my “mail form” header part, mail will come into inbox so plz tell me the importance of “mail from” header part and also if there is any other constraint to increase delivery to inbox in yahoo ISP tell me taht Too

    plz help


    1. It’s a huge topic :-), I will try to keep in a simple way (even I am trying to understand the mail-server behavior). The “From:” header is important because most of the mail-server rely on the person who is sending the e-mail, since it depends on the “Reply To” section on the receiver end (even though it can controllable).

      In most cases, people (we software engineer) just write “From:”, “To:”, “Subject:”, & “Body:” leaving most of the other attributes behind like “Reply To:”, “Return Path:”, etc.

      I am guessing this could be the valid reason why sometimes our email rejected if there is a change in the “From:” header. Like I said this particular topic is vast, if you want to understand that in detail, please have a look at this link:

  2. cupcake for everyday of the month says:

    After going over a handful of the blog articles on your site,
    I seriously appreciate your way of writing a blog.
    I saved as a favorite it to my bookmark site list and will
    be checking back in the near future. Take a look at my web
    site too and tell me how you feel.

  3. Sangeeta says:

    I am facing similar problem. my mail script is working fine when i use my company mail id in header’s From part.That is I am able send mail from my company ‘s mail id but same this doesn’t work when I use my gmail or yahoo id in header’s From address.
    Anyone please please please help me out.

  4. Azmy says:

    Thanks alot for the post, It surely helps alot of other people who are going through this annoying problem after you, I was banging my head searching fr a solution and here you come with the best solution 🙂 way to go! (y)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s