sending email with PHP (2)

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);

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">