Sending mail on a Win32 machine with PHP

Configuring mail on a Win32 machine

I have PHP set up locally on my personal computer but I never used the mail function on my PC.
So I had no experience when a site moved from a Linux box to a PC. There was a problem with the mail function, but I had no idea what the problem was, because the error message uninformatively said 'Warning: Unknown error in script.php on line XX.'

It turned out the mail server settings in php.ini were not configured correctly. I was unable to send mail until they were configured properly. A shortcut I discovered that saved me from constantly stopping the local installation of Apache and PHP on my PC, to edit the php.ini file, as I tried to discover the correct settings was the ini_set() command.

Function ini_set(configuration option, new value)

Sets the value of a configuration option. This value is not permanently changed, it is valid only for the script being executed/run, and will revert back to the values in the php.ini file once the script is finished running.

Note: Not all configuration values can be changed with this function. Take a look at PHP: Manual: ini_set to find out which options can be changed.

PHP Code:

<?php
ini_set
("SMTP", "your mailserver");

ini_set("sendmail_from", "your email-adress");

mail("account@server.com","testing mail on win32 via php","Test to make sure that mail is configured correctly.");
?>

Once I was able to successfully send an email, I then edited the php.ini file in this section:

PHP.ini values:
[mail function]
; For Win32 only.
SMTP = mailsender.server.com

; For Win32 only.
sendmail_from = account@server.com

The SMTP server is typically the name or IP address of the SMTP server of your ISP where you have an account. This server would be the one that you would enter in an email program like Eudora, Outlook etc. as your smpt server when setting up an email account.

Sendmail_from is your email address.

      Subscribe in a reader