#!/usr/bin/perl
## Configuration section
$SENDMAIL="/usr/lib/sendmail"; # the server path to your sendmail program
$from_address="me\@mydomain.com"; # your own email address
$subject="A recommendation"; # the subject line for the email
$cc_address="foo\@bar.com"; # copies of each referral will be sent here
## End configuration
# tell Perl we want to use CGI.pm
use CGI;
# create a constructer for CGI.pm
$query=CGI::new();
# get the form parameter 'action'
$action=$query->param("action");
# if we have a value of 'send' for $action, it means that the
# script has been called by the form below, so we should have
# enough information
# to actually send the email. If not, print the form.
if ($action eq "send") { &send;}
else { &form;}
exit;
sub form {
# get the referring URL
$url=$ENV{'HTTP_REFERER'};
# Print out the form screen
print "content-type: text/html\n\n";
print qq^
<!-- put your own html here -->
<html>
<head>
</head>
<body>
<center>
<h2 class="name">tell a friend</h2>
To tell a friend about: <br><a href="$url">$url</a><br>
please enter your name, and both your own and
your friend's email addresses below, then click 'send'
<form action="tell-a-friend.cgi" method="post">
<table>
<tr><td>Your Name:</td>
<td><input type="text" size="15" name="name"></td></tr>
<tr><td>Your email:</td>
<td><input type="text" size="15" name="source"></td></tr>
<tr><td>Your friend's email:</td><td>
<input type="text" size="15" name="destination"></td></tr>
<tr><td colspan="2" align="center">
<input type="submit" value="Send"></td></tr>
</table>
<input type="hidden" name="url" value="$url">
<input type="hidden" name="action" value="send">
</form>
</center>
</body>
</html>
^;
}
sub send {
# get the form values using CGI.pm
$url=$query->param("url");
$name=$query->param("name");
$source=$query->param("source");
$destination=$query->param("destination");
# check that the email addresses are valid, and that a name is
# supplied
if ($source!~ /^(\w¦\-¦\_¦\.)+\@((\w¦\-¦\_)+\.)+[a-zA-Z]{2,}$/
¦¦
$destination!~ /^(\w¦\-¦\_¦\.)+\@((\w¦\-¦\_)+\.)+[a-zA-Z]{2,}$/
¦¦ $name eq ""
) {&error}
# open a 'pipe' to the email program, so we can print directly
# to it (or die trying)
open (FP, "¦ $SENDMAIL -t -oi -oeq") or die;
#Now print the email headers
print FP "To: $destination\n";
print FP "Cc: $cc_address\n";
print FP "From: $from_address\n";
print FP "Subject: $subject\n\n";
# The next line prints the body of the message.
# '$name', '$source' and '$url' will be replaced by the
# values supplied in the form
print FP "Hi,\n$name ( $source ) \n
thought that you might be interested in the following page:\n
$url\nand has asked us to email you to tell you about it.\n\n";
# Close the pipe to the email program
close(FP);
# Print out some html for a 'thank you' screen:
print "content-type: text/html\n\n";
print qq^
<html>
<head>
</head>
<body>
<center>
<h2 class="name">Thank you</h2>
Your email has been sent.
</center>
</body>
</html>
^;
}
sub error {
# something's wrong! Replace the HTML below with your choice
# of error screen
print "content-type: text/html\n\n";
print qq^
<html>
<head>
<title>Error!</title>
</head>
<body>
<h1>Whoops!</h1>
There seems to be a problem - please use the back button
on your browser and check that the details you gave are
correct.
</body>
</html>
^;
# as we have no valid details we want to leave the program now:
exit;
}
Question: What changes do I make to this to get it to work?