Home Contact

Timmy Kokke

…just sorting my bubbles…

News




Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged

Twitter












Tag Cloud


Archives

Post Categories

Image Galleries

Silverlight

Syndication:

Sending email from PHP on Windows using IIS

The blog engine I’m writing for the WinPHP Challenge is really getting shape. At certain points in the application I would like to send an email. Luckily SMTP is supported by IIS. Here’s a small how-to to get it up and running and send an email from your php app using IIS.

 

Setting Up and Configuring IIS

Start by going to the ServerManager on you Server. Most often this is the server you’ll be running your php website on.

Go to Add features in the Features summary section. 

AddFeatures

Check SMTP Services in the Add Features Wizard and hit install. Now wait for the installation to finish.

 

Open IIS6 Manager under Administrative Tools -> Internet Information Services 6.0 in the Start Menu. Note that although I’m running Windows Server 2008 with IIS7, the configuration of SMTP makes use of the management console from IIS6.

Under [SMTP Virtual Server], click your right mouse button and select properties from the context menu.

SMTP-Properties

Go to the Access Tab and hit the Relay button.Relay

Add a new entry to the list by clicking the Add button and enter 127.0.0.1 in the single computer entry field.

Relay-Restrictions

Hit Ok two times to apply the new settings.

For testing purposes I added the IP of my local machine to the list too. This way I can use the same server to send emails from the code I’m working on.

 

Configuring Php

To make Php send emails you need to make some configurations. Basically there are two options.

In case you’re only going to use the SMTP server in a single project project and do not want it to interfere with other projects, you can set the configuration from within your php code by adding the following lines anywhere before sending the email:

ini_set('SMTP','localhost' ); 
ini_set('sendmail_from', 'administrator@YourWebsite.com');

Another way, to make global use of these settings, add the next lines to your php.ini file.

[mail function]
SMTP = localhost
sendmail_from = me@example.com

Make sure you restart your server after making these changes, to be sure they’re loaded.

 

Sending an Email

The last part is sending an actual email. Sending an email uses the php mail function. The mail function takes at least three parameters:

bool mail(string $to, string $subject, string $message)

Finally, here’s a small example on how to combine it all and send the email:

<?php
ini_set('SMTP','localhost'); 
ini_set('sendmail_from', 'Your.Own@Address.com'); 

$to = 'Someone@somewhere.com';
$subject = 'Example subject';
$body = 'With an example body…'; 

mail($to, $subject , $body);
?>

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Sunday, May 31, 2009 9:52 AM

Feedback

# re: Sending email from PHP on Windows using IIS

Thanks for sharing this information. I got a chance to know about this.
2/3/2010 9:22 PM | Partybets Bonus

# re: Sending email from PHP on Windows using IIS

dear sir there is no problem on local host but what if the web server where i hosted the files is iis7 and there my php mail script is not working.........have ne solutions??? 6/17/2010 8:10 AM | shoaib

# re: Sending email from PHP on Windows using IIS

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. I think it may be help all of you. Thanks 12/25/2010 12:17 PM | example

# re: Sending email from PHP on Windows using IIS

nice tip. thaks a lot 12/25/2010 6:12 PM | Bloger

# re: Sending email from PHP on Windows using IIS

Thanks for all the info. Hey stop by http://www.grabfreebie.info you might find it informative as well 2/18/2011 2:56 AM | eric

# re: Sending email from PHP on Windows using IIS

i was searching for send mail with php, and just got here.. thxfor the explanation. btw, how we make it weekly send mail for subscriber? any hint? 3/6/2011 10:19 PM | rainer

# re: Sending email from PHP on Windows using IIS

Pretty good tip, thanks. I've always hated IIS ;) 3/16/2011 6:43 PM | Chuck

# re: Sending email from PHP on Windows using IIS

I have searched so many times about this topic 3/17/2011 1:21 PM | Buy Canon G12

# re: Sending email from PHP on Windows using IIS

Its opportunity are so fantastic and working style so speedy. I think it may be help all of you. 3/22/2011 7:16 AM | cheap wedding invitation

# re: Sending email from PHP on Windows using IIS

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy. I think it may be help all of you. Thanks 3/22/2011 11:23 PM | étui housse cuir portable

# re: Sending email from PHP on Windows using IIS

PHP is something that for a very long time I've been trying to figure out. But some for some reason I'can't seem to wrap my head around it.

It's different 3/23/2011 3:47 AM | Nikon COOLPIX S6100

# re: Sending email from PHP on Windows using IIS

This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles Real Air Max 5/5/2011 11:42 AM | Jenny

# re: Sending email from PHP on Windows using IIS

you have told us usefull things about WinPHP Challenge. many thanks 6/21/2011 8:11 AM | cheap Louis Vuitton outlet

# re: Sending email from PHP on Windows using IIS

I know nothing about ISS before I come here. thank you 6/21/2011 8:15 AM | burberryoutlet

# re: Sending email from PHP on Windows using IIS

Just wanted to let you know that this was awesome I fixed the same issue in no time, I went ahead and posted on my blog the same but giving you all the credits possible. Thanks again for the info. 9/9/2011 7:15 PM | Andre

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: