|
CGI - Sending Email |
tutorial by Matt |
This is the part you have probably been waiting for.
It is very fun to send an automatic EMail back to your user but the
problem with this is that not many free servers support it and all
servers are very strict about it. If you are planning on making a
program to spam all you users email account or whatever then I am
sure you account will be terminated and you IP address will be put
into the servers log and you will never be allowed to join again.
Another problem with Sending EMail is that only UNIX servers
support it because it uses a UNIX program called sendmail. Tripod
does not allow you to use sendmail be they have made their own
mail module for you to use. You must go to tripod yourself and
configure it. In order to send an email you must specify the
address that it will be sent to and your email address and it always
help to have a subject. We are just going to do a nice simple example
for today I will just explain the components of a EMail script
because I can't be sure that it will work for you if I do a
script, because every server may respind differently. first
you would declare the path to the UNIX program sendmail
which is usually(but not always) /usr/sbin/sendmail -n -t -oi
Now you have to think, how are you going to get the users email address or
whatever? simple a nice HTML textbox. If you want,you can do it through an HTML
page calling the cgi script for processing or you can simply have cgi print
the form as you learned last section. The syntax for using send mail is lised below:
open (MAIL, "| $sendmail") or
die "Couldn't send email.";
print MAIL << EOF;
From: $from
To: $address
Subject: $subject
$body
EOF
close MAIL;
//}
The first thing here is the filehandle MAIL. You can change MAIL to whatever you want that
is just the filehandle so you can easily call it. Next you see a variable named $sendmail,
this is the variable that you would assign early on in the script to the path for the UNIX
program sendmail. So you would assign it like this: $sendmail = "/usr/sbin/sendmail -n -t -oi";
The next line tell the server that if it can't open the file then it should exit and
print the message supplied there. The next line print to sendmail until it finds
the word EOF which means End Of File. From To and Subject are required after
line 3. The variable used there should be assigned earlier just like the
$sendmail variable. That is how simple it is to send a nice friendly
email to your users.
You may now move onto the next section Flat-File Databases
|
|
|
|