Solved

refer this site

Posted on 2006-07-07
9
261 Views
Last Modified: 2013-12-25
I have tried exhaustivley to configure several perl and CGI scripts - but everytime I think I got it - it does not do as I anticipate. If this is a question already answered please direct me. I need a CGI script to process Form input from the user who visits the site and when "Submit" is clicked the email address  that was input by the user - is used as the recipient address and sent a pre-formatted plain text ascii message recommending the site. Thats it , can you assist
0
Comment
Question by:SilentOne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17065447
Describe the problems you are having in more detail. Saying it does not do what you anticipate is too vague to offer much help.

Make sure the path to perl is correct, the first line of the script might be something like: #!/usr/bin/perl
Make sure to upload the script in ASCII (text) mode and not binary mode if using an FTP program.
Set the file permission to 755 or whatever is recommended.
Check the server error logs if you can.

You can also search script archives like www.hotscripts.com for canned "refer this site" scripts.
0
 

Author Comment

by:SilentOne
ID: 17066645
hi Perl_Diver:

Thanks for the quick reply. i think I miscommunicated. I have little or no Perl expertise. I waws hoping to get a script from the archives located here. It seems to me the basic problem with all of the scripts I attempted to use is that ti will send email to the hidden address in the perl script but not the address enntered in the email text box of the html. Below is a perl script that accepts the input from the user and even redirects correctly but nothing goes to the email that is put in the input box:


The script is called mailer.cgi


 #!/usr/bin/perl

use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);

######################## Program Header #########################################
##
##  Copyright (C) 2004  Poetic Pollution
##  Script Name: BareBonesMailer
##  Version: 0.2.4
##  URL: http://poeticpollution.net/scripts/BareBonesMailer/
##
##  This program is free software; you can redistribute it and/or
##  modify it under the terms of the GNU General Public License
##  as published by the Free Software Foundation; either version 2
##  of the License, or (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  Please read the full GNU GPL: http://www.gnu.org/copyleft/gpl.html
##
#################################################################################

######################## User Defined Variables ########################
##  Edit as needed...

# Path to sendmail
$mailProg = "/usr/sbin/sendmail -t";

# Your email address and be sure to leave the \ in front
# of the @ or else you'll get errors.. ;)
$toEmail = "inspiremail@\incron.com";

# Domains that are able to use the mailer script
# Enclose in quotes and seperate each with a comma
@valid_referrers = ("inspirationpress.com","");

# Redirect them to this URL:
# This should be a pre-existing file with a thank you
# message or something similar..
$redirectURL = "http://www.inspirationpress.com/index.html";

# Your time zone difference from GMT
$offSet = "-7";

# Military time 0 = off  1 = on
$milTime = 0;


######################## Engage Mailer ########################
##  Don't Edit Below Here Unless You Know How...

$valid_http_referrer = 0;

foreach(@valid_referrers) {
      if($ENV{'HTTP_REFERER'} =~ /^https?:\/\/(www\.)?$_/i) {
            $valid_http_referrer = 1;
            last;
      }
}

unless($valid_http_referrer) {
      &headerFooter;
      print qq|You are coming from the wrong page. Please go back and try again..\n|;
      print @footer;
      exit;
}

$fromName = param('nameField');
$fromEmail = param('emailField');
$formContents = param('formField');
$formSubject = param('Subject');

unless($fromName) {
      &headerFooter;
      print qq|The <b>Name</b> field is required. Please go back and try again..\n|;
      print @footer;
      exit;
}

unless(($fromEmail) && ($fromEmail =~ /.*\@.*/)) {
      &headerFooter;
      print qq|The <b>Email</b> field is required. Please go back and try again..\n|;
      print @footer;
      exit;
}

unless($formContents) {
      &headerFooter;
      print qq|You must include a message of some sorts. Please go back and try again..\n|;
      print @footer;
      exit;
}

@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
@time = gmtime(time + (3600 * $offSet));

$newMinSec = sprintf("%02d:%02d",$time[1],$time[0]);
$newDay = sprintf("%02d",$time[3]);
$years = $time[5] + 1900;

if ($milTime) { $hours = sprintf("%02d",$time[2]); }
else {
      if ($time[2] < 12) { if ($time[2] == 0) { $hours = 12; } else { $hours = $time[2]; } $amPm = " AM"; }
      else { if ($time[2] > 12) { $hours = $time[2] - 12; } else { $hours = $time[2]; } $amPm = " PM"; }
}

$dateFormat = "$newDay/$months[$time[4]]/$years at $hours:$newMinSec$amPm";

$remoteAddress = $ENV{'REMOTE_ADDR'};
$remoteHost = $ENV{'REMOTE_HOST'};
@subnetNumbers = split (/\./, $remoteAddress);
$packedAddress = pack ("C4", @subnetNumbers);
($remoteHost) = gethostbyaddr ($packedAddress, 2);

open(MAIL, "|$mailProg") || die "Unable to open Mail Program.";
print MAIL "To: $toEmail\n";
print MAIL "From: $fromEmail\n";
print MAIL "Subject: $formSubject\n";
print MAIL "Date: $dateFormat.\n\n";
print MAIL "Name: $fromName <$fromEmail>\n";
print MAIL "$remoteHost / $remoteAddress\n";
print MAIL "Browser: $ENV{'HTTP_USER_AGENT'}\n";
print MAIL "Subject: $formSubject\n\n";
print MAIL "$formContents\n";
close(MAIL);

print "Location: $redirectURL\n\n";

exit;


sub headerFooter {
# ------------------------------------------------
open (FILE, "mailer-template.html") || die "Unable to open the Mailer Template for reading..";
@HTMLFile = <FILE>;
close(FILE);

for ($a = 0; $a < @HTMLFile; $a++) { if ($HTMLFile[$a] =~ /<!-- mailer output will be here -->/) { $foundIt = 1; last; } }
unless($foundIt) { die "HTML comments not found in the Mailer Template.."; }

for ($i = 0; $i < $a; $i++) { push(@header, $HTMLFile[$i]); }
for ($i = $a; $i < @HTMLFile; $i++) { push(@footer, $HTMLFile[$i]); }

print "Content-type: text/html\n\n";
print @header;
}
0
 
LVL 8

Expert Comment

by:Perl_Diver
ID: 17066719
fix your error first:

$toEmail = "inspiremail@\incron.com";

should be:

$toEmail = "inspiremail\@incron.com";
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:SilentOne
ID: 17067036
Hi  Perl_Diver

I fixed the error and tested it - the results were the same it redirected ok , but did not send the email
0
 

Author Comment

by:SilentOne
ID: 17067065
Perl_Diver  I apologize after a closer look at the from used

this script is desgined to allow the user to send email to me - not to refer to a friend:

<htm>
<form method="post" action="http://www.inspirationpress.com/cgi-bin/mailer.cgi">

Your Name:<br>
<input type="text" name="nameField" size="30" maxlength="100"><br><br>

Your Email:<br>
<input type="text" name="emailField" size="30" maxlength="100"><br><br>

Tell us what's up:<br>
<textarea name="formField" rows="7" cols="30" wrap></textarea><br><br>

<input type="hidden" name="Subject" value="BareBonesMailer Submission">

<center><input type="submit" value="Send It!"></center>
</form>
</htm>


And thats what I mean. I simply dont have enosugh exposure with perl to know whats going on. Is there any scripts in the EE archive that allows the user to refer the site their on to a friend - thats basically all  I need.



















And that s what I mean. I simply dont have the expertise
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17067097
replace:
  $toEmail = "inspiremail\@incron.com";
by:
  $toEmail = param('emailField');
  $toEmail =~ s/[^a-zA-Z0-9.@-]//g;  # quick&dirty input validation
0
 

Author Comment

by:SilentOne
ID: 17068278
hi ahoffmann

I got an internal server error - Im not sure where to look for the specific error
0
 
LVL 8

Accepted Solution

by:
Perl_Diver earned 500 total points
ID: 17069197
if you want a "refer this site" script I suggest looking on www.hotscripts.com or other archive for a script. The one you posted is not good, I would not use it. No form field validation is never a good idea, no maximum content length set, file uploading not disabled. Don't use it.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 17069260
> I got an internal server error
please check your script from command line
0

Featured Post

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question