Solved

refer this site

Posted on 2006-07-07
9
254 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
  • 4
  • 3
  • 2
9 Comments
 
LVL 8

Expert Comment

by:Perl_Diver
Comment Utility
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
Comment Utility
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
Comment Utility
fix your error first:

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

should be:

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

Author Comment

by:SilentOne
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:SilentOne
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> I got an internal server error
please check your script from command line
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now