Sending Email with PHP mail() on a Windows Server
The Problem
Sending email using PHP on a Windows IIS server is not as simple as it is when using a Linux server. On a typical setup the mail() function probably won’t work without some tweaking.
Why?
When sending email using PHP’s mail() function on a Linux server, PHP uses sendmail to process the email, but the same is not possible on Windows IIS servers. On Windows servers you may be required to specify an SMTP server to connect to, the port and the sending email address.
The Solution
The settings outlined above may already be specified on your php.ini configuration file, but on a shared server that will probably not be the case. Instead you can specify them within your script using PHP’s ini_set() function.
The code below shows how the SMTP server, port and sender email address can be set:
ini_set('SMTP', 'mail.example.com'); ini_set('smtp_port', '25'); ini_set('sendmail_from', 'example@example.com');