This chapter describes: How to check the mail
server on your local Windows system and how to send an email through
PHP. This is a great way to get visitors to contact you and you to
contact members without opening up a software application.
Sending Emails
This chapter describes:
- How to check the mail server on your local Windows system.
- How to send an email through PHP.
Using Local Windows System as a Mail Server
If you are running your Web server on a local system and not connected to the Internet,
you need to set up your local system as a mail server to test the email function in PHP.
If you are running a Linux/Unix system, setting up a mail server is easy. Just run sendmail
as daemon.
If you are running a Windows system, setting up a mail server is a little bit harder.
But most of the time, your local Windows system is probably already running a mail server.
Here is how you can check this:
1. Go to Control Panel / Services, and make sure Simple Mail Transfer Protocol is running.
2. Open a command window, and run the following command:
>telnet localhost 25
220 localhost Microsoft ESMTP MAIL Service, Version: 6.0.2600.1106...
help
214-This server supports the following commands:
214 HELO EHLO STARTTLS RCPT DATA RSET MAIL QUIT HELP AUTH BDAT VRFY
quit
221 2.0.0 localhost Service closing transmission channel
If you got similar outputs as above, your mail server is running ok.
Sending an Email with PHP
First you need to verify \php\php.ini to make sure the following settings:
SMTP = localhost
smtp_port = 25
Now run the following PHP script, MailTest.php:
<?php # MailTest.php
# Copyright (c) 2002 by Dr. Herong Yang, http://www.herongyang.com/
#
mail("nobody","Testing","This is a test.","From: herong@localhost");
?>
Then go check to see the email is delivered or not in a command window:
>dir \inetpub\mailroot\drop
... d9765b3001c54a1200000001.eml
>type \inetpub\mailroot\drop\d9765b3001c54a1200000001.eml
x-sender: herong@localhost
x-receiver: nobody@localhost
Received: from localhost ([127.0.0.1]) by localhost with Microsoft...
Subject: Testing
To: nobody
From: herong@localhost
Return-Path: herong@localhost
......
This is a test.
If you can follow me to here, you have successfully configured your local system
to send emails with PHP.
|