The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

[SOLVED] PHP's mail(): proper way to send a 'From' header

SeñorAmorSeñorAmor !!!Registered User regular
edited July 2008 in Help / Advice Forum
Greetings folks. I seem to be having a problem with PHP's mail() function and sending 'From' headers properly. Here's my setup:

I have a site I set up for a client that has a form their clients can fill out to submit some data. When the form is submitted, I have PHP gather the data and create the body of an email which is then sent to both the owners of the site and back to the person who submitted the data. Because the server hosts multiple sites, I am sending an additional 'From' header so the email doesn't appear to come from the hostname of the server itself (nobody@web.mysite.com).

As per PHP's documentation of the mail() function, I am sending the header like so:
From:  sender@othersite.com\r\n

I am getting bounce emails from certain ISPs (AOL, Roadrunner, some local ISPs) saying the sender's domain does not exist. It seems that either mails are coming from my hostname (nobody@web.mysite.com), or those ISPs are reading the additional headers incorrectly. Unfortunately, this is not acceptable. People aren't getting their emails, and the hammer is coming down on me.

As far as I know (based on the lack of bounce emails), this worked fine on PHP4, but with our new webserver (running PHP5), I'm experiencing problems. Far as I can tell, the mail() function has not changed between versions.

I'm stumped here and need to get this fixed asap. I've tried 'From' and 'FROM', tried a 'Name Here <name@isp.com>' format, and tried terminating with double newlines with and without the carriage return. Nothing seems to work. I've even gone so far as to edit php.ini with a default from address, but that doesn't appear to have fixed anything either.

Please help.

Thanks in advance.

*Edit*
Because I do not have a DNS entry for my hostname, the 'domain does not exist' error I'm seeing in the bounce emails is correct. I do not wish to add a DNS entry for it, as that does fix the 'From' header issue to begin with, so I would appreciate it if you did not make that suggestion. :)

SeñorAmor on

Posts

  • bowenbowen Sup? Registered User regular
    edited July 2008
    If I'm reading this right, you're using your server as an open-relay type system? You want to send the email as if it's coming from the said submitter?

    EDIT:

    That said, I did a little digging, it seems that you're doing everything right:
    mail($to, $subject, $message, $from);
    

    This tends to be the format people usually use.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen Sup? Registered User regular
    edited July 2008
    Change your sendmail server to use a FQDN so that you can relay properly.

    Also, check to see which email, by default, php is sending with. This will probably eliminate the problem.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • PirateJonPirateJon Registered User regular
    edited July 2008
    Since it's limited to a few ISPs, my first guess is an anti-spam problem with DNS reverse lookups.

    FCrDNS explained.
    http://en.wikipedia.org/wiki/Forward_Confirmed_reverse_DNS

    AOL email best practices. Quote "All email servers connecting to AOL's mail servers must have valid, meaningful, non-generic reverse DNS records"
    http://postmaster.aol.com/guidelines/bestprac.html

    AOL's DNS tester tools:
    http://postmaster.aol.com/tools/index.html

    PirateJon on
    all perfectionists are mediocre in their own eyes
  • Vladimir7Vladimir7 Registered User regular
    edited July 2008
    I like to use the PHPMailer library. Don't have to deal with all the headers and stuff being proper.

    Vladimir7 on
  • SeñorAmorSeñorAmor !!! Registered User regular
    edited July 2008
    Problem solved. There's an extra '-f' flag you can send that allows you to force the Return-path email address. Did some testing and all parties are now receiving emails.

    This can be closed down. Thanks!

    SeñorAmor on
This discussion has been closed.