University of Bahrain
Information Technology College
Computer Science Department
Semester 1, Year 2006/2007
ITCS 373: Class Lab Work
E-commerce2
Instructor: Dr. Eshaa M. Alkhalifa
Since we have a
few problems with sending emails we can install an email server to work next to
our application server.
- Start by installing the email server that I provided,
simply by clicking next over and over until it is fully installed. Make sure that your AppServ program is
off by going to programs/AppServ/Control Server by Service This will make a little feather appear
at the bottom right hand corner of the screen. If you right-click on the feather and
then click on open Apache monitor, you will see the monitor pop up
screen. Make sure your server is
highlighted then click on the stop button.
The dot next to the server will turn from green to red. If it is not off, you may run into
problems installing your software.
- Once your email server is installed and starts up,
you can go to localhost to see the screen displayed there. Take a look at how it works so that you
can get used to the server because you will have to turn this screen off
and using direct commands if you wish to turn your Apache server on.
- In the future times that you start your email server,
all you will see of it is the boat along with a sail on the lower right
hand corner of your screen.
- If you right click on it, and then click on show, you
will see a popup window.
- Click on the yellow mechanical cog to alter the
options. Open a cmd window
and type there ipconfig /all and copy the DNS server entry. Type or paste the DNS server entry into
the first field under the General tab. Make sure that the following are all
checked; Automatically start the server, Allow relay, allow creation of accounts
from web, when bouncing include original message.
- Do NOT write anything in the localhost slot. Instead, click on the local domains
tab, and type localhost then click add, then type localhost.com
then click add again.
- Click on OK to confirm your changes.
- Click on the image of two people standing. Then click on the folded paper to the
left. The most important fields are
the user name, the password and confirming the password.
- Now go the localhost screen, and login then send an
email to yourself. Make sure the server
works.
- Then go back to the options screen which is the
yellow cog, and place a check mark in front of Do not Use web interface. Although using the web interface is fun,
it causes a serious problem, when you run this server next to an apache
server because this is a very simple email server. Click on OK to save your changes.
- Now go to the lower right hand side of your screen
and open the apache panel to start the server. If you get any errors, go back to check
if you set up the mail server correctly.
- If you wish to test it, you can set up outlook
express to use it. Go to tools/accounts/ Click on add then mail. Write the email address myemail@localhost.com. Type the incoming and outgoing mail
servers as localhost.com.
Type your user name and password, and then click on next
then finish.
- Send an email to yourself and check that it works.
- Now that your email server is working with the Apache
on the same computer, we can first test if we can write a php script that
can send email.
- Start by customizing your php.ini file by doing the
following
Open the php.ini file
Find
[mail function]
; For
Win32 only.
SMTP = mail.silvertair.com
smtp_port = 25
; For
Win32 only.
;sendmail_from
= eshaa@silvertair.com
; For
Unix only. You may supply arguments as
well (default: "sendmail -t -i").
;sendmail_path =
; Force
the addition of the specified parameters to be passed as extra parameters
; to
the sendmail binary. These parameters will always replace the value of
; the
5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
Check all the fields above and alter them as appropriate;
SMTP = localhost.com
sendmail_from = myemail@localhost.com
- Save your php.ini file.
- Write a new php script and call it emailscript.php
and save it in the www folder. Copy
and paste the following code to the script.
<?
$to = "ealkhalifa@admin.uob.bh";
$from =
"myemail@localhost.com";
$subject =
"subject is..";
$contents =
"this is a test email from a script";
$from_header =
"From: $from";
if($contents !=
"")
{
//send mail - $subject & $contents come
from surfer input
mail($to, $subject, $contents,
$from_header);
// redirect back to url visitor came from
//header("Location:
$HTTP_REFERER");
print("<HTML>You did it</HTML>");
}
else
{
print("<HTML><BODY>Error,
no comments were submitted!");
print("</BODY></HTML>");
}
?>
- Replace my email address with yours. Save your script, then run it (You
should know how to run it by now).
You should see, "you did it" on the screen. Check your email box to see that you
have received the email.