简体   繁体   中英

php mail() function and IIS

I have coded a site with PHP. Our client deployed the site to IIS. They installed PHP 5.2 but mail() function doesnt work on their server.

They added this config file in the www folder:

web.config:

<configuration>
    <system.webServer>
        <handlers>
            <remove name="PHP- fastcgi" />
            <add name="PHP - FastCGI" path="*.php" verb="*" 
                 modules="FastCgiModule" 
                 scriptProcessor="C:\Php\php-cgi.exe" resourceType="Unspecified" />
        </handlers>
        <defaultDocument>
            <files>
                <add value="default.php" />
                <add value="index.php" />
            </files>
        </defaultDocument>
    </system.webServer>
</configuration>

The following error is generated by the mail() function:

server error - 500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.

I know there must be a simple solution with an edit of the php.ini file. But the person in charge has said that they couldnt edit php.ini and we have to code contact page with asp.

Is there any way to send mail using php in this case?

There was a long outstanding bug in the mail() function in PHP 5.2 on Windows:

Bug #28038 Sent incorrect RCPT TO commands to SMTP server

The From: header was being parsed incorrectly by the mail() function and most properly behaved RFC compliant mail servers will reject it as an invalid address.

This is now fixed in PHP 5.2.11+ (I have tested this with PHP 5.2.14, PHP 5.2.17 and PHP 5.3.6). So I'd find out the exact version of PHP 5.2.x your application is running under and see if it's affected by this bug.

However, I'd recommend using SwiftMailer instead. You get a lot more control over stuff like configuring the outgoing mail server, authentication and so on and it doesn't rely on using the built-in mail() function. We have several customers using this on our shared hosting platform and they're very happy with it.

you can try and set options with

ini_set()

function

ini_set reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM