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: firstname.lastname@example.org’ . “\r\n” .
‘Reply-To: email@example.com’ . “\r\n” .
‘Return-Path: firstname.lastname@example.org’ . “\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:
RETURN-PATH – http://en.wikipedia.org/wiki/Return-path
REPLY-TO – http://emailuniverse.com/ezine-tips/?id=179