Php is running on II6, so I have to have the mail options set in php.ini....

I have several different pages (actually different websites) that are hosted on the same server. Obviously I don't want a mail function from website B to use domain A's sendmail_from setting in php.ini.

I looked at ini_set, but it doesn't allow you to change sendmail_from in the ini (at least it's not on the list of available options in the appendix listing for ini_set).

If I leave sendmail_from commented out in the php.ini, it just won't send the mail, even if I set a from address in the options of the mail() function.

Is there anyway to code a page so that it ignores or changes what is in the php.ini file and follows it's own "from" directives?

    You could set, a different Reply-To value for each site, perhaps?

      Well, that is what I'm looking to do, but how? They all are hosted on the same server and therefore use the same php.ini file....

        In the additional headers arg for the mail() function, add a "Reply-To: someone@somplace.com", e.g.:

        $headers = "From: someone@somplace.com\r\n";
        $headers .= "Reply-To; someone@somplace.com\r\n";
        $headers .= "X-Mailer: PHP/" . phpversion();
        
        mail($to, $subject, $message, $headers);
        

          You could make a general "config.php" in each site's web space, and add site-specific configurations like so:

          <?php
          ini_set('sendmail_from', 'noreply@site1.com');
          ?>

          Then, you would simply include the appropraite config.php in each script.

          Alternatively, you could simply set this address each time you send mail:

          ini_set('sendmail_from', 'noreply@site1.com');
          mail($to, $subject, $message);

          EDIT: Setting the addresses in the custom headers, as mentioned above, is probably easier yet (just make sure to change that semicolon after Reply-To to a colon 😉).

            bradgrafelman wrote:

            I would say make a general "config.php" in each site's web space, and add site-specific configurations like so:

            <?php
            ini_set('sendmail_from', 'noreply@site1.com');
            ?>

            Then, you would simply include the appropraite config.php in each script.

            Alternatively, you could simply set this address each time you send mail:

            ini_set('sendmail_from', 'noreply@site1.com');
            mail($to, $subject, $message);

            I've definately been staring at this computer too long today--I was looking for "mail_from" instead of "sendmail_from" on the ini_set() appendix list of available options 🙂 Thanks for making me look again guys!!

            I've tested it with just adding in the ini_set() just before the mail function, no config.php file needed, and with the sendmail_from line commented out in the php.ini file. Works like a charm--Woot!

            I'm going to mark this resolved.

              Write a Reply...