Jump to content

Webform And Sendmail


gmwade

Recommended Posts

I am new to TCH and scripting and want to send a webform to a single email address. I found out that CGIemail is not supported but that I can use Sendmail. So, I have read the forums and tried some segments of code but I can't seem to get anything to work. I searched the documentation in TCH and don't see any basic instructions or templates as examples. Would someone please provide:

1. Basic instructions

2. Sample CGI form (e.g myform.cgi)

 

Is it something like:

#!/usr/bin/perl

  $sendmail = '/usr/sbin/sendmail -t';

  $recip = 'myname\@mywebsite.com';

 

3. Sample of HTML form action

 

Is it something like:

<form action="http://www.mywebsite.com/cgi-bin/myform.cgi" method="POST">

 

4. Are there any special services that need activation? (I see how to make the permssions 755; not sure if the upload is in ASCII but it looks OK when viewing under CODE/EDIT)

5. Does the cgi form go in the CGI folder under Public_html? I presume that you can make a cgi form using wordpad and then change the file type.

 

Any tips would be appreciated. Some basic instructions for how to use Sendmail on TCH would be most helpful for a newcomer...nothing fancy...just sending a single webform to an email address.

Link to comment
Share on other sites

OK Thanks. I will check it out. At first glance, it looks like there are too many options for someone who has not worked with scripts. Yesterday, I found samples out on the web but they did not seem to apply to TCH's paths and syntax and I couldn't get it to work. It would be helpful to be able to cut and paste someone elses code who uses TCH (for processing a single web form to an email recipient) so the paths and syntax would work. I thought someone may have a template somewhere with instructions so I wouldn't spend days of research to get this working but I will explore hotscripts tomorrow and see if anything pops out. I was unable to find anything along these lines in the CPanel documentation.

Link to comment
Share on other sites

Welcome to the forums gmwade :)

 

Here is a sample script that I use. You will need a copy of cgi-lib.pl which you can find using Google. Place the scripts in your "cgi-bin" folder and change the permissions to 755. Hope that helps.

 

>#!/usr/bin/perl
$mailprog = '/usr/sbin/sendmail -t' ;

require ('cgi-lib.pl');

&ReadParse(*field);


$First_Name = $field{'First_Name'} ;	 
$Last_Name = $field{'Last_Name'} ;	 
$E_mail = $field{'E_mail'} ;	 
$Phone = $field{'Phone'};
$Comments = $field{'Comments'} ;	 

$message = "" ;
$found_err = "" ;


#get current date and time
&get_date;


$errmsg = "<p>Field 'First Name' must be filled in.</p>\n" ;

if ($First_Name eq "") {
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>Field 'Last Name' must be filled in.</p>\n" ;

if ($Last_Name eq "") {
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>Please enter a valid email address</p>\n" ;

if ($E_mail !~ /.+\@.+\..+/) {
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>You must enter a 'Phone' number.</p>\n" ;

if ($Phone eq "") {
$message = $message.$errmsg ;
$found_err = 1 ; }


$errmsg = "<p>Field 'Comments' must be filled in.</p>\n" ;

if ($Comments eq "") {
$message = $message.$errmsg ;
$found_err = 1 ; }

if ($found_err) {
&PrintError; }


$recip = "you\@yourwebsite.com" ;

open (MAIL, "|$mailprog");
print MAIL "Reply-to: $E_mail\n";
print MAIL "From: $E_mail\n";
print MAIL "To: $recip\n";
print MAIL "Subject: Webform request\n";
print MAIL "\n\n";
print MAIL "On: ".$long_date."\n" ;
print MAIL "--------------------------------------\n" ;
print MAIL "\n" ;
print MAIL "Name:          ".$First_Name." ".$Last_Name."\n" ;
print MAIL "E-mail:        ".$E_mail."\n" ;
print MAIL "Phone:         ".$Phone."\n" ;
print MAIL "--------------------------------------\n" ;
print MAIL "\n" ;
print MAIL "Comments:      ".$Comments."\n" ;
print MAIL "--------------------------------------\n" ;
print MAIL "\n\n";
close (MAIL);


$recip = $E_mail ;

open (MAIL, "|$mailprog");
print MAIL "Reply-to: you\@yourwebsite.com\n";
print MAIL "From: you\@yourwebsite.com\n";
print MAIL "To: $recip\n";
print MAIL "Subject: Your message has been received\n";
print MAIL "\n\n";
print MAIL "Thank you ".$First_Name." for using our on-line message form.\n" ;
print MAIL "\n" ;
print MAIL "We will respond to your query as quickly as possible.\n" ;
print MAIL "\n" ;
print MAIL "You submitted the following:\n" ;
print MAIL "\n" ;
print MAIL "Name:          ".$First_Name." ".$Last_Name."\n" ;
print MAIL "E-mail:        ".$E_mail."\n" ;
print MAIL "Phone:         ".$Phone."\n" ;
print MAIL "------------------------------------\n" ;
print MAIL "Comments:      ".$Comments."\n" ;
print MAIL "------------------------------------\n" ;
print MAIL "\n" ;
print MAIL "If you require a response you should receive one within 48 hours, if not please \n";
print MAIL "submit this information again by replying to this message.\n" ;
print MAIL "\n" ;
print MAIL "Thank you,\n" ;
print MAIL "\n" ;
print MAIL "Your Name\n" ;
print MAIL "http://www.yourwebsite.com\n" ;
print MAIL "\n\n";
close (MAIL);

print "Content-type: text/html\n\n";
print "<HTML>\n" ;
print "<HEAD>\n" ;
print "<TITLE>Thank You!</TITLE>\n" ;
print "<style>\n" ;
print "body {\n" ;
print 'color: "#000000";'."\n" ;
print 'font-family: "arial";'."\n" ;
print "font-size: 10pt;\n" ;
print "}\n" ;
print "a:link { color: blue; text-decoration: none }\n" ;
print "a:visited { color: darkred; text-decoration: none }\n" ;
print "a:active { color: cyan; text-decoration: none }\n" ;
print "a:hover { color: red; text-decoration: underline }\n" ;
print "</style>\n" ;
print "</HEAD>\n" ;
print '<BODY bgcolor="white">'."\n" ;
print "<center>\n" ;
print '<table border="0" width="90%">'."\n" ;
print "<tr><td>\n" ;
print '<H2><font color="red">Thank you '.$First_Name.'!</font></H2>'."\n" ;
print "We appreciate your taking the time to write.\n" ;
print "<P>\n" ;
print "We\'ve mailed off your query to be processed as soon as possible.  We\'ve sent you an e-mail \n" ;
print "confirmation with the information you entered on the form.\n" ;
print "<P>\n" ;
print "Information submitted:<br>\n" ;
print "Comments: ".$Comments."\n" ;
print "<P>\n" ;
print "We will reply to you as quickly as possible if necessary.\n" ;
print "Your request is important to us.\n" ;
print "<HR>\n" ;
print '<H3>Back to the <A HREF="http://www.yourwebsite.com">Home Page</A></H3>'."\n" ;
print "</td></tr></table></center>\n" ;
print "</BODY></HTML>\n" ;


sub PrintError { 
print "Content-type: text/html\n\n";
print "<HTML>\n" ;
print "<HEAD>\n" ;
print "<TITLE>Validation Errors!</TITLE>\n" ;
print "</HEAD>\n" ;
print '<BODY bgcolor="white">'."\n" ;
print "<center>\n" ;
print '<table border="0" width="90%">'."\n" ;
print "<tr><td>\n" ;
print '<p align="center"><font color="#FF0000" face="Arial"><big><strong>Webmail Form'."\n" ;
print "Processing Error</strong></big></font></p>\n" ;
print "\n" ;
print '<p align="left"><font face="Arial" color="#000080"><strong>You forgot to enter one or more'."\n" ;
print "values:</strong></font></p>\n" ;
print "\n" ;
print '<p align="left"><font color="#000000" face="Arial"><strong>'.$message.'</strong></font></p>'."\n" ;
print "\n" ;
print '<p align="left"><font face="Arial" color="#000080"><strong>Please click your browser\'s'."\n" ;
print "Back button and try again.</strong></font></p>\n" ;
print "</td></tr></table></center>\n" ;
print "</BODY></HTML>\n" ;

exit 0 ;
return 1 ; 
}

sub get_date {

  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

  if ($sec < 10) {
     $sec = "0$sec";
  }
  if ($min < 10) {
     $min = "0$min";
  }
  if ($hour < 10) {
     $hour = "0$hour";
  }
  if ($mon < 10) {
     $mon = "0$mon";
  }
  if ($mday < 10) {
     $mday = "0$mday";
  }

  $month = ($mon + 1);
  $year = ($year + 1900);

  @months = ("January","February","March","April","May","June","July","August","September","October","November","December");

  $date = "$hour\:$min\:$sec $month/$mday/$year";

  chop($date) if ($date =~ /\n$/);

  $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
}      

 

In your web page to use this script you build your form using this:

 

><form action="http://www.yourwebsite.com/cgi-bin/yourscript.pl" method="post">

Link to comment
Share on other sites

Bruce:

Thanks for your feedback. I have been swamped with work and am only getting to start on this now. This may sound a bit off but is the script file saved as "myscript.pl" or "myscript.cgi"? I am presuming it is "myscript.pl" since that is what is called in the html piece but wanted to be sure. I was able to find and download "cgi-lib.pl" and put it in the cgi-bin folder and will put the other script file there as well but was unclear as to the exact file name. Please clarify if you can. Then I will worry about tweeking the template to hopefully get things working.

GW

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...