Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Help With Form To Mail Script

complete Beginner

10:26 pm on May 27, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 1, 2005
votes: 0

Hi! I was hoping someone could tell me what I've done wrong with the following script that has come from my webserver help files. It is a simple "form to e-mail" that I have to use on my Windows Server that doesn't support ASP, just PHP (Pearl?).
The script takes a comment and passes it to the right e-mail address, which is great, but I don't know how to get it to then direct the user to my thankyou page.
I am a complete novice at this and don't really understand what I'm doing, it's taken me three hours to get to the stage where I'm getting the e-mails I want.... I'm probably just missing something really simple. Many thanks in advance!
The script:

use OLE;
use CGI;
$jmail = CreateObject OLE "JMail.SMTPMail";
$form = new CGI;
$domain = $ENV {'SERVER_NAME'};
$referer = $ENV {'HTTP_REFERER'};
$url = $referer;
$url =~ s/^http:\/\///i;
$url =~ s/^www\.//i;
$domain =~ s/^www\.//i;
$Sender = "noreply\@$domain";
$SMTPServer = "smtp.$domain:25";
$Header = "Originating-IP",
$jmail->{ServerAddress} = $SMTPServer;
$jmail->{Sender} = $Sender;
$jmail->{Subject} = $Subject;
$jmail->AddRecipient ($Recipient);
$jmail->{Body} = $Body;
$jmail->{Priority} = $Priority;
$jmail->AddHeader ($Header);
if ($url =~ m/^$domain/)
$mailmessage = "mail sent";
$mailmessage = "mail was not sent.
Incorrect Referer";
print "Result: $mailmessage Recipient: $Recipient";
print "Sender: $Sender SMTP Server:
print "Subject: $Subject Referer: $referer";
print "Domain: $domain url: $url ";

8:27 pm on May 29, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
votes: 12

(Resisting the urge to point out potential exploits in script)


This will send the user to your thank you page provide you have not already "printed" anything else to the browser:

$thanks = 'http://'.'YourDomain.com/YourThanks.Page'."\n\n";
print "Location: $thanks\n\n";

[Edit]Changed variable so that WW parser wouldn't try to hyperlink the URL, the $thanks var does not actually need all the concatenation[/Edit]

[edited by: IanKelley at 8:33 pm (utc) on May 29, 2007]

8:28 pm on May 30, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 1, 2005
votes: 0

Many Thanks Ian!