|
Custom Search
| |
|
How to use PHP and Microsoft SMTP Virtual Server to send emails
IIS has a built-in SMTP Virtual Server that can be used by PHP mail() function to send emails. If you are connected to Internet, emails will be sent out. If your computer doesn't have Internet connection, you can still use it to send emails but instead actually sending out emails, they will be stored in C:\Inetpub\mailroot\Queue folder. The email filename would be in a format like NTFS_2b15732801c54a4f00000002.EML The good thing about this practice is that you can test your PHP mail() function locally and offline. For example, you can double click the email filename and examine subject, body text, To and From address, etc. The default mail function setup in php.ini looks like this:
[mail function] ; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. The above code can be left as is. "SMTP = localhost" means you will use local SMTP Virtual Server that came with IIS for email message relay. However, in order for PHP mail() function to work locally, you must do two things:
Steps to enable SMTP server for local relay 1. Open IIS, right click SMTP Virtual Server. Select Properties from the
dropdown menu. 2. Select Access tab and click the Relay button. 3. The Relay Restrictions window is opened. Click the Add button. 4. When the window opens, type in 127.0.0.1 in IP address field. Then click
OK. 5. Now local IP address is granted for relaying. Then click OK. Note: You can also use your ISP's SMTP server. But for development, testing, and debugging purpose, use localhost should be fine.
[mail function]
; For Win32 only. SMTP = your ISP's SMTP server smtp_port = 25 ; For Win32 only. How to fix a common error Here is a common error you may enconter:
mail() [function.mail]: Failed to connect to mailserver at "localhost"
port 25, verify your "SMTP" and "smtp_port" setting
in php.ini or use ini_set()
Many people have tried to fix this error by changing the default mail function setting in php.ini file. The default mail function setup in php.ini looks like this:
[mail function]
; For Win32 only. SMTP = localhost smtp_port = 25 ; For Win32 only. The default setting does not have to be changed. Instead, check your SMTP server availability and configuration. 1. Check if SMTP server has been installed. Microsoft SMTP Virtual Server is bundled with Internet Information Server (IIS). So, if you don't have IIS installed, you don't have SMTP server. To look for IIS, follow this path from Start menu. Start -> Settings -> Control Panel -> Administrative Tools -> Internet Services Manager Internet Services Manager has three basic components: Default FTP Site, Default Web Site, and Default SMTP Virtual Server.
If you can't find Internet Services Manager, you need to install it. Start -> Settings -> Control Panel -> Add/Remove Programs When the window opens, click Add/Remove Windows Components on the left hand side navigation bar. Next, click Components button to bring up Windows Components Wizard. Find Internet Information Services (IIS) and install it. 2. If SMTP server has already been installed, check if it is running. 3. If SMTP server is running, check if it has been configured to use TCP port 25. 3.1 Open IIS, right click on SMTP Virtual Server. Select Properties from the dropdown menu. Then, click Advanced button on the General tab.
3.2 When the new window opens, check the TCP port number.
3.3 Next, click Connection button.
3.4 When the new window opens, check the TCP port number. Change it to 25 if it is not.
|
Copyright © 2024 GeeksEngine.com. All Rights Reserved. This website is hosted by HostGator. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
Home | Feedback | Terms of Use | Privacy Policy |