Geeks With Blogs

News


Timmy Kokke's Blog

↑ Grab this Headline Animator

Timmy Kokke at Blogged
Timmy Kokke …just sorting my bubbles…

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

Posted on Sunday, May 31, 2009 9:52 AM WinPHP , PHP , Windows Server 2008 , IIS7 | Back to top


Comments on this post: Sending email from PHP on Windows using IIS

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Thanks for sharing this information. I got a chance to know about this.
Left by Partybets Bonus on Feb 03, 2010 9:22 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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???
Left by shoaib on Jun 17, 2010 8:10 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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
Left by example on Dec 25, 2010 12:17 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
nice tip. thaks a lot
Left by Bloger on Dec 25, 2010 6:12 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Thanks for all the info. Hey stop by http://www.grabfreebie.info you might find it informative as well
Left by eric on Feb 18, 2011 2:56 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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?
Left by rainer on Mar 06, 2011 10:19 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Pretty good tip, thanks. I've always hated IIS ;)
Left by Chuck on Mar 16, 2011 6:43 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
I have searched so many times about this topic
Left by Buy Canon G12 on Mar 17, 2011 1:21 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Its opportunity are so fantastic and working style so speedy. I think it may be help all of you.
Left by cheap wedding invitation on Mar 22, 2011 7:16 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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
Left by étui housse cuir portable on Mar 22, 2011 11:23 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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
Left by Nikon COOLPIX S6100 on Mar 23, 2011 3:47 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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
Left by Jenny on May 05, 2011 11:42 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
you have told us usefull things about WinPHP Challenge. many thanks
Left by cheap Louis Vuitton outlet on Jun 21, 2011 8:11 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
I know nothing about ISS before I come here. thank you
Left by burberryoutlet on Jun 21, 2011 8:15 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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.
Left by Andre on Sep 09, 2011 7:15 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Hello,

I did not same in server php.ini except "sendmail_from = me@example.com" this one our programmer is adding in their PHP code. Now the mails are sending fine to all the users but for few users I am getting bounce back message and my mails are not delivering to them. I have listed the errors that I faced. Please advise where the issue is?

Reporting-MTA: dns;ip-0A80323A
Received-From-MTA: dns;ip-0A80323A
Arrival-Date: Wed, 22 Feb 2012 19:32:18 +0530

Final-Recipient: rfc822;abc@example.com
Action: failed
Status: 5.5.2
Diagnostic-Code: smtp;504 5.5.2 <ip-0A80323A>: Helo command rejected: need fully-qualified hostname

Thank you,
Left by Mohamed Nazar on Feb 24, 2012 7:34 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
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?
Left by John Cutts on Apr 21, 2012 9:23 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
I am not able to start smtp server it gives error "message occurs when you start SMTP service"
what should i do???
Left by sagar kumar soni on Jul 12, 2012 8:45 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Hi .. It works

Thanks
Left by Sushil Shinde on Nov 12, 2013 9:38 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Thank you!
Left by Paul on Aug 05, 2014 3:06 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Top stuff ! - The ini_set additions in a web page or two resolved a major issue re non receipt of php mail

Thanks
Left by Neil on Oct 06, 2014 4:46 PM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
This tutorial is gold. Helped me out immensely. Internet gold for you.
Left by camthaman on Mar 21, 2016 2:07 AM

# re: Sending email from PHP on Windows using IIS
Requesting Gravatar...
Resolved
Thanks
Left by selva on Oct 24, 2016 6:00 PM

Your comment:
 (will show your gravatar)


Copyright © Timmy Kokke | Powered by: GeeksWithBlogs.net