Configure PHP email function for windows server.
We learnt about sending mail from PHP with linux sendmail in this series of tutorial. On windows we don’t have pre configured email sever on mostly server. to fix this PHP mail function on windows, we can do with ini_set php function or setting it up on php.ini.
Setting php.ini
if you have access to php.ini ,you can change the default global value .
[mail function] SMTP = localhost sendmail_from = me@example.com
Setting at run time ini_set
we can change this configuration at run time with ini_set function as given below.
ini_set('SMTP','localhost'); ini_set('sendmail_from', 'fromaddress@domain.com');
Example
ini_set('SMTP','localhost'); ini_set('sendmail_from', 'fromaddress@domain.com'); $to = 'toaddress@domain.com'; $subject = 'Sample subject'; $body = 'message body '; mail($to, $subject , $body);
