Solved

Email page to friend

Posted on 2000-03-19
50
710 Views
Last Modified: 2013-12-25
Hi,

I want to site visitors to be able to email an article to a friend, in exactly the same way as is done at the following URL:

http://www.ellisinsurance.com/business/articles/bus_ins_how_to.htm

While I say "exactly" -- it doesn't have to be exact -- if you have a better solution.

I do know on this particular site they are using a cgi script to accomplish the above task.

Thanks!

Rowby
0
Comment
Question by:Rowby Goren
  • 28
  • 20
  • 2
50 Comments
 

Expert Comment

by:venky75
ID: 2634716
Hi there,
 visited the site and found out what u needed.The article is being derived from the database and being added to the body of the mail. if u have a database/text files also u can do the same. The code u can use (on submission of form with the name and email particulars) is:

use CGI;
$q=new CGI;
$friendname=$q->param("friend name");
$friendmail=$q->param("friend mail");
$articlename=$q->param("subject");
#The article name can be passed as hidden field.
$articlebody=$q->param("article");
# Pass the value as another hidden field

$flags = "-t";
$mailer  = '/usr/lib/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname
From: $friendmail
Subject: $articlename
$articlebody
!;
close (MAIL);

I hope this 'll work out ..
0
 
LVL 1

Expert Comment

by:lambda
ID: 2634745
venky75 :
You made a slight mistake...

It should be,
To: $friendmail
From: $yourEmail

Am I right?
0
 

Accepted Solution

by:
venky75 earned 200 total points
ID: 2634782
Hi there,

Sorry about that part. This new code should help solve it.
(Here the sender_name, sender_mail, friend_name and friend_mail should be the name of respective fields :your name, your mail, your friend name, and your friend mail.)

use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$friendmail=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("subject");
#The article name can be passed as hidden field.
$articlebody=$q->param("article");
# Pass the value as another hidden field

$flags = "-t";
$mailer  = '/usr/lib/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);

I hope this 'll work out ..

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2635914
Hi,  Thanks for the solution.  I have to be gone today and will look closer at it tonight.  I might have a couple of questions -- and then I'll award the points!

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2642712
Just to show you my complete ignorance of most of cgi-stuff, please confirm that I put this file in my cgi-bin with an extension, such as "email.setup", and just make sure I reference the fields in on my html page...right???


0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2650045
Hi,

I'm having some problems getting the script to work.  I did make some changes, which may be what is causing the problem.  Here is my revised script and a list of the changes I made:

1)  Added to the first line: #! /user/local/bin/perl line

2)  Changed your:
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$friendmail=$q->param("sender_name");
$sendermail=$q->param("sender_mail");

to read:
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
(because you'll see that you repeated "friendmail" twice, which I assume was a mistake, but I may be wrong.)

3)  I inserted the name of the text tile "test-article.txt"  (which I put in the same directory as your script)

4)  For mailer I changed the path (per my server's insrtuctions to:
$mailer  = '/usr/sbin/sendmail';

Here is my modified version of your script.  (followed by other info)

#! /usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$articlebody=$q->param("test-article.txt");
# Pass the value as another hidden field

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);


--- The following is the HTML of the form page:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>New Page 1</title>


<meta name="Microsoft Border" content="none">
</head>

<body background="images/line-bg1.gif">

 <form method="post" action="/cgibin/email_articles/test-article.txt">
<table width="28%" border="0" bgcolor="#FFFFFF" align="center" cellspacing="0">
<tr bgcolor="#660000"> <td colspan="2"><font face="Arial, Helvetica, sans-serif" size="2"><b><font color="#FFFFFF">Mail
this article to a friend!</font></b></font></td></tr> <tr> <td width="32%"><font face="MS Sans Serif, Arial, Geneva" size="1" color="#000000">Your
name:</font></td><td width="68%"> <input type=text name=sender_name size="20"> </td></tr> <tr>
<td width="32%"><font face="MS Sans Serif, Arial, Geneva" size="1" color="#000000">Your
e-mail:</font></td><td width="68%"> <input type=text name=sender_mail size="20"> </td></tr>
<tr> <td width="32%"><font face="MS Sans Serif, Arial, Geneva" size="1" color="#000000">Friend's
name:</font></td><td width="68%"> <input type=text name=friend_name size="20"> </td></tr> <tr> <td width="32%"><font face="MS Sans Serif, Arial, Geneva" size="1" color="#000000">Friend's
e-mail:</font></td><td width="68%"> <input type=text name=friend_mail size="20"> </td></tr>
<tr> <td width="32%"> <input type=hidden name=t value=do_you_have_collision_1.htm>
</td><td width="68%"> <input type=reset name="reset" value="Clear"> <input type=submit name="Send" value="Send!">
</td></tr> </table></form>

 &nbsp;</body>

======

My server uses cgibin instead of cgi-bin and has an alias that redirects any cgi-bin to cgibin.

Here is the path to the form page:
http://www.mdsutton.com/test-email-article.html

Here is the path to the cgi bin, including the text file:

http://www.mdsutton.com/cgibin/email_articles/test-article.txt

==========================

I don't have access to the server error logs, but the Web2010 person looked at them and said there was a problem with the recipient.

I've made some changes to the script after he told me that, but I don't think I did anything in the recipient area.

========

Any thoughts?



0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2650076
Here is a simplified version of my FORM PAGE's HTML (got rid of colors and background, etc, for easier reading)

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>New Page 1</title>


<meta name="Microsoft Border" content="none">
</head>

<body>

 <form method="post" action="/cgibin/email_articles/test-article.txt">
<table width="28%" border="1" align="center" cellspacing="0">
<tr bgcolor="#660000"> <td colspan="2"><b>Mail this article to a friend!</b></td></tr> <tr> <td width="32%">Your
name:</td><td width="68%"> <input type=text name=sender_name size="20"> </td></tr> <tr>
<td width="32%">Your
e-mail:</td><td width="68%"> <input type=text name=sender_mail size="20"> </td></tr>
<tr> <td width="32%">Friend's
name:</td><td width="68%"> <input type=text name=friend_name size="20"> </td></tr> <tr> <td width="32%">Friend's
e-mail:</td><td width="68%"> <input type=text name=friend_mail size="20"> </td></tr>
<tr> <td width="32%">
</td><td width="68%"> <input type=reset name="reset" value="Clear"> <input type=submit name="Send" value="Send!">
</td></tr> </table></form>

 &nbsp;</body>

0
 
LVL 1

Expert Comment

by:lambda
ID: 2650439
<form method="post" action="/cgibin/email_articles/test-article.txt">

The form action should be the path of the CGI program. It should have .cgi or .pl extension.
0
 
LVL 1

Expert Comment

by:lambda
ID: 2650465
BTW,

$articlebody=$q->param("test-article.txt");

If by this, you mean to read the contents of a file into the variable $articlebody, the correct code is:

$filePath = "/usr/file/test-article.txt"; # the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);
0
 
LVL 1

Expert Comment

by:lambda
ID: 2650491
#! /usr/local/bin/perl

This line (with the space in between) could also be a problem.
Else the path may not be correct.
Do verify...
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2650504
Thanks for the comments.

Also you should know I just got an email from tech support that says that the server uses smtp  -- which was different from what the live tech person told me (sendmail).

I sent the tech dept an email asking for clarification.

Also, in case you're interested, here is the command to look at the error logs on my server (domain:n http://www.mdsutton.com)

Cut and paste from a tech support email:

Rowby:

You can view the error log. Here is the command:

tail -20 /web/logs/error_log

Substitute the 20 with however many lines you want to see.

DonW
Web2010


0
 
LVL 1

Expert Comment

by:lambda
ID: 2651998
smtp is just the mail protocol & sendmail is the Unix program used for sending mails. No problems there.

Could you view ur errorlog? If you could tell us what error was written there?

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2652051
I received one response from tech support saying they support both mail systems.

Regarding the error log, I am waiting clarification from web2010 tech support.  But here is the email I sent them, perhaps you can figure it out.

=====


FIRST EMAIL:
Do I have access to our error logs.  I don't think we do, but
I
> want to be sure.  If not, can you recomend a debugging tool that I can (I
> assume) put on the server to I can debug when necessary.
>
> Rowby
> Error:            Thanks!
>
> Rowby Goren
>




========

THEIR REPLY
From: techsupport@web2010.com [mailto:techsupport@web2010.com]
Sent: Thursday, March 23, 2000 9:20 AM
To: rowby@earthlink.net
Subject: Re: PR-2 Tech Support Needed


Hello,

You can view the error log. Here is the command:

tail -20 /web/logs/error_log

Substitute the 20 with however many lines you want to see.

DonW
Web2010
rowby@earthlink.net said:

======

MY REPLY (Still waiting for their response.

Hi Don,

Do I issue it as follows:

http://www.mdsutton.com/tail -20 /web/logs/error_log

If so, I'm getting an error message.  "Page cannot be found."

Thanks for any clarification.

=======

IN CONCLUSION:

Lambda, I shhould hear from them by the morning, but again, maybe you can figure how to use the above command to see the error logs.


Thanks!!!
     Rowby
0
 
LVL 1

Expert Comment

by:lambda
ID: 2652175
U can use the "tail" command from ur command prompt (telnet to the server), not in the browser.

So I can't see it, 'cos I don't have access to ur server.
0
 
LVL 1

Expert Comment

by:lambda
ID: 2652205
Meanwhile why don't you try something like this....

Test HTML page: (TestPage.html)
==============

<html>
<head><title>Testing</title></head>

<body>
<form method="post" action="/cgibin/justatest.pl">
<input type="Submit" name="submit" value="Test It!">
</form>
</body>
</html>


justatest.pl (saved in your /cgibin directory)
===============

#!/usr/local/bin/perl

print "Content-type:text/html\n\n";
print "Success!";


Tell me what happens.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2653144
THis is getting interesting :)

Look's like I'll have to fire up
telnet.  

Here's what I did.  I had to rename the extension to *.cgi" in accordance with my server's faq.  Here's my revised script

#!/usr/local/bin/perl

print "Content-type:text/html\n\n";
print "Success!";

I named the above file justatest.cgi
changed permissions to 777 (for now)

and modified your html file:

<html>
<head><title>Testing</title></head>

<body>
<form method="post" action="/cgibin/justatest.cgi">
<input type="Submit" name="submit" value="Test It!">&nbsp;
</form>
</body>
</html>

But got the following error:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, Webmaster and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.




HERE's the FAQ from my web server.


FAQ
The first line of each script should read: #! /usr/local/bin/perl
(please also see below)

One exception is if you are using PerlShop, it should read:

#! /usr/local/bin/perl5.003

Reference the script using "cgibin", NOT using "cgi-bin"

Use ".cgi" extensions for all scripts

If a script calls another file within your account, but the script does NOT
require a URL, you need to use the system path.

/web/guide/<domainname>/...
<- if file resides in root
/web/guide/<domainname>/cgibin/...
<- if file resides in cgibin

0
 
LVL 1

Expert Comment

by:lambda
ID: 2654203

The problem *has to be* the first line as I insisted...
#!/usr/local/bin/perl
I can't think of anything else ...

Just try changing that line to
#!/usr/bin/perl
and see what happens. It's just a guess, that ur perl might be there.

Once more, can you go to the location "/usr/local/bin/" and check if there is a file called 'perl' there?
(or perhaps make ur Admin check it for you)
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2654377
DO you mean the space between the #! and the /usr?

current version:

#! /usr/local/bin/perl

And that it should be like this instead?

#!/usr/local/bin/perl


Thanks

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2654488
Progress so far. Removing the space got me to the following URL:

http://www.mdsutton.com/cgibin/email_articles/test-article.txt

(with an internal server error page)

I think we're getting there.  It's finally trying to access the test-article.txt file, but still not quite getting there.

So I need to know where to insert your following modification into the script (which is on the bottom of this post.)

But I need to know where the following:

$filePath = "/usr/file/test-article.txt"; # the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

========== latest version of script follows ====

#!/usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$articlebody=$q->param("test-article.txt");
# Pass the value as another hidden field

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);


0
 
LVL 1

Expert Comment

by:lambda
ID: 2655888
rowby: what is the name of ur perl program? I mean the one you've posted just now?
It should have .cgi extension...

I don't understand why this URL is called... From ur HTML you have to call the name of the perl program as the form action.

http://www.mdsutton.com/cgibin/email_articles/test-article.txt


0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2655996
Ooops.  Sorry. Fixed that so it's calling the cgi, program, not the txt file.

Am not gettiing the misconfiguration error, but a bad page url error.

And I think that will be fixed as soon  as you tell me where to put in the following code:

$filePath = "/usr/file/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);
0
 
LVL 1

Expert Comment

by:lambda
ID: 2656513
Remove this line:
$articlebody=$q->param("test-article.txt");

and replace it with the code. Change the first line ($filePath = "/usr/file/test-article.txt";) to the absolute path of the file.

But I don't think that is the problem ....

Do give me these details...

 - Did you rename your cgi program as test-article.cgi?
 - Did you upload the test-article.cgi to the following location?
    ... /cgibin/email_articles/test-article.cgi
    (The bad URL error is because the cgi file cannot be found in that location.)
 - What OS do YOU work on? Windows?
 - How do you save/upload your file to the server?
 - Another thing I have been asking you for a long time... is your perl located at /usr/local/bin/perl ? If you can't check, do ask somebody to.

0
 
LVL 1

Expert Comment

by:lambda
ID: 2656526
It most definitely has to be the path to the perl. I tried running our little test program from this location:

http://www.mdsutton.com/cgibin/justatest.cgi

And I got an Internal Server Error.
Since there are only 3 lines in it, the error has to be the first line.

Do verify the location of perl in your server.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656548
Well (configuration error) don't worry I'll increase the points to 300 by the time this is finished (!)

Here's the latest version of the cgi script (I inserted the snippet where I thought it should go:

#!/usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$filePath = "/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);


====
And here's the html code from the calling page:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>M.D. Sutton Insurance</title>


<meta name="Microsoft Border" content="none">
</head>

<body>

 <form method="post" action="/cgibin/email_articles/email-article.cgi">
<table width="28%" border="1" align="center" cellspacing="0">
<tr bgcolor="#660000"> <td><b>Mail this article to a friend!</b></td></tr> <tr> <td width="100%">Your
name:<input type=text name=sender_name size="20">
    <p>Your
e-mail:<input type=text name=sender_mail size="20"> </p>
    Friend's
name:<input type=text name=friend_name size="20">
    <p>Friend's
e-mail:</p>
 <input type=text name=friend_mail size="20">
    <p> <input type=reset name="reset" value="Clear"> <input type=submit name="Send" value="Send!">
    </p>
  </td></tr> </table></form>

 &nbsp;</body>

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656555
After posting my last comments I saw your earlier messages from early this morning.

For some reason I was not notified by email about those earlier Experts exchanges messages.  I will return when I have checked out your earlier suggestions.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656573
I guess by the time we figure this out, *I* will become a cgi expert :)

To answer your questions:

1. I did rename my cgi program as: email-article.cgi  (that is the exact name -- and I see it right now in my server's...

/mnt/web/guide/mdsutton/cgibin/email_articles

....cgi directory  (cut and paste of the exact location)

2.  Using cute-ftp, I just now went to usr/local/bin and found the file named perl


3. Am using windows 98

4  O iuse cute ftp  -- uploaded in ascii mode the cgi file.  I'll download it now to a different directory and view it to make sure it's not corrupted.

Nope, it looks fine.  Here again is the code from the cgi file I just downloaded:

#!/usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);

P.S.  Here is, from the web2010 faq's info regarding perl and directories:

If you have a custom CGI script that you need to use, simply upload it to your personal
"cgibin". Here are some helpful tips to follow when installing Perl scripts:

Utilize any directory except "cgi-bin" for your own scripts.
We recommend placing them in your cgibin directory to help consolidate them.

Upload in ASCII transfer mode (and NOT BINARY mode)
Those using Fetch should use Text mode (not Raw Data)

The first line of each script should read: #! /usr/local/bin/perl
(please also see below)

One exception is if you are using PerlShop, it should read:

#! /usr/local/bin/perl5.003

Reference the script using "cgibin", NOT using "cgi-bin"

Use ".cgi" extensions for all scripts

If a script calls another file within your account, but the script does NOT
require a URL, you need to use the system path.

/web/guide/<domainname>/...
<- if file resides in root
/web/guide/<domainname>/cgibin/...
<- if file resides in cgibin

Substitute the path to the file beginning with your domain name. Your domain name is the
directory name of your account.

======
Interestingly look at that space in the first line. I'm going to contact tech support and ask them about that space.

---- Rowby



0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656579
P.S.  Please look at the code in the cgi script I just posted. I insterted the text file name path before I read your comments on how I should have inserted it.  So my screw up might be there.

Thanks
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656587
Just to keep everything on track, I did a cut and paste on the test file.  And here it is:


#!/usr/local/bin/perl

print "Content-type:text/html\n\n";
print "Success!";

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656601
I sent your test cgi file (with and without the space in that first line) to Web2010 tech support.  

Let's see what their comments are about that 3 line test.  

That sound bring an interesting response.  I sent it via their email support so they might not get back ot me today.

Perhaps we should BOTH take today off :)


Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656821
I was able to get telnet access so I did the following:

===================

I will now run the following:

http://www.mdsutton.com/cgibin/justatest.cgi

Now running telnet to look at error log:
[Sat Mar 25 11:13:52 2000] [error] [client 209.179.245.168] Premature end of scr
ipt headers: /web/guide/mdsutton/cgibin/justatest.cgi


Now I'll run the test email form:
http://www.mdsutton.com/test-email-article.html

error log:
[Sat Mar 25 11:20:23 2000] [error] [client 209.179.245.168] malformed header fro
m script. Bad header=No recipient addresses found i: /web/guide/mdsutton/cgibin/
email_articles/email-article.cgi
================

Once again, here is the cgi code. I'll download all three files from the site right now to make sure that it's exactly as up there in the server and cgibin:

1)  email-article.cgi  (cut and paste of file name and cut and paste of the following code:

#!/usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;
close (MAIL);


2.  justatest.cgi  (located in cgibin)

#!/usr/local/bin/perl

print "Content-type:text/html\n\n";
print "Success!";

============
html of
http://www.mdsutton.com/test-email-article.html  (URL is  cut and paste from address browser)

html code:  (cut and paste from file I just downloaded from server:)

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>M.D. Sutton Insurance</title>


<meta name="Microsoft Border" content="none">
</head>

<body>

 <form method="post" action="/cgibin/email_articles/email-article.cgi">
<table width="28%" border="1" align="center" cellspacing="0">
<tr bgcolor="#660000"> <td><b>Mail this article to a friend!</b></td></tr> <tr> <td width="100%">Your
name:<input type=text name=sender_name size="20">
    <p>Your
e-mail:<input type=text name=sender_mail size="20"> </p>
    Friend's
name:<input type=text name=friend_name size="20">
    <p>Friend's
e-mail:</p>
 <input type=text name=friend_mail size="20">
    <p> <input type=reset name="reset" value="Clear"> <input type=submit name="Send" value="Send!">
    </p>
  </td></tr> </table></form>

 &nbsp;</body>




0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656824
Just this minute received the following from web2010 tech support:

Hi,

Yes, there is a space between #! /usr/  
thanks

samj

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2656838
well, I put a space in justatest and still got the same error.

I'll just wait until Web2010 looks at the justatest script and offers an expalnation.

Rowby

Yawn!
0
 
LVL 1

Expert Comment

by:lambda
ID: 2657047

The space in the first line is just fine. After I asked abt the space, I tried in my server with & without the space, & the code worked both ways.

I can't imagine why our test script is not working.

The error in your errorlog:
"Premature end of scr
ipt headers: /web/guide/mdsutton/cgibin/justatest.cgi"

usually occurs when you miss out the Content-type line.

The second error :
"malformed header from script. Bad header=No recipient addresses found i: /web/guide/mdsutton/cgibin/
email_articles/email-article.cgi"

occurs if the recipient address is not given, etc.

I can't imagine the problem ... but try changing the following lines of email-article.cgi :

print MAIL qq!
To: $friendname\<$friendmail\>
From: $sendername\<$sendermail\>
Subject: $articlename
$articlebody
!;

to this...

print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;

I am not very optimistic, but do try.

0
 
LVL 1

Expert Comment

by:lambda
ID: 2657067
rowby, another thing... can you just tell me if
#!/usr/local/bin/perl
is the *very first* line in the script? There should be NO line (blank or other wise ) before it. Please verify.

0
 
LVL 1

Expert Comment

by:lambda
ID: 2657074
... and keep ur fingers crossed.. !!!!
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2657193
1:  #!/usr/local/bin/perl
is indeed the *VERY* first line of the script in the file. I know this is important. (!)

2) I modified as you suggested, but still go the configuration error. I've made so many "minor" modifications to this script -- maybe you should look at the exact current version.

3)  Regarding the test script, maybe that will provide the clue to all of this when I hear back from Web2010 tech support -- asking them why it didn't work.

CUT AND PASTE FOLLOWS (no space at top of file):
#! /usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;
close (MAIL);
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2658270
Just a test is now working.

I changed permissions from 777 to 755.

(!)

http://www.mdsutton.com/cgibin/justatest.cgi

So I guess that was the problem. I changed permissions to  email-article. and ran it again, and got the following in the error logs:


syntax error at email-article.cgi line 42, near "!;"
Execution of email-article.cgi aborted due to compilation errors.
[Sun Mar 26 08:34:33 2000] [error] [client 209.179.244.64] Premature end of scri
pt headers: /web/guide/mdsutton/cgibin/email_articles/email-article.cgi
w116:/mnt/web/guide/mdsutton#    


====
Here is the script that the above run (I downloaded it again so we have the exact version:)

#! /usr/local/bin/perl
use CGI;
$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");
#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$flags = "-t";
$mailer  = '/usr/sbin/sendmail';
$mailer1 = '/usr/bin/sendmail';
$mailer2 = '/usr/sbin/sendmail';

if ( -e $mailer){
    $mail_program=$mailer;
} elsif( -e $mailer1){
    $mail_program=$mailer1;
} elsif( -e $mailer2){
    $mail_program=$mailer2;
} else {
    print "Content-type: text/html\n\n";
    print "I can't find sendmail, shutting down...<br>";
    print "Whoever set this machine up put it someplace weird.";
    exit;
}
$mail_program = "$mail_program $flags ";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;
!;
close (MAIL);
=======

The above was modified by me based on comments, and I may have improperly inserted the various suggestions.  So another look by you would be appreciated.  

Rowby
0
 
LVL 1

Expert Comment

by:lambda
ID: 2659526
Oh yes, when I asked you to replace the mail-sending code, I think I had included the !; also.

Just remove that line.

And some other unwanted lines also can be removed from it, if you can tell me where your sendmail program is located.

Or else I will just assume that it's at
the location, /usr/sbin/sendmail. And make slight modifications.


I'll just repeat the entire code for you...

#! /usr/local/bin/perl
use CGI;

$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename=$q->param("Test Email From Rowby");

#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$mail_program = "/usr/sbin/sendmail -t";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;
close (MAIL);

print "Content-type: text/html\n\n";
print "mail sent succesfully.";


Do try this.

0
 
LVL 1

Expert Comment

by:lambda
ID: 2659547
rowby, I don't think it was the problem with the permissions. Usually you need to give only execute permissions to all. But changing from 777 to 755...???
And if it were because permissions were denied, it would have said, "You don't have permission to view this ..." etc.

Did you get some feedback from ur SysAdmin?

Anyway, I am glad to hear it's working at last!!!

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2659679
Success!

Thanks for all your help

http://www.mdsutton.com/test-email-article.html
0
 
LVL 1

Expert Comment

by:lambda
ID: 2660202
** SIGH OF RELIEF **

I checked it, and I found a little problem... There was no subject for the mail.

Change the following line:

$articlename = $query->param ("Test Email From Rowby");

to this:

$articlename = "Test Mail From Rowby";

Missed it earlier.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2660578
Actaully I caught it and put it in.

Can you do one more thing. Instead of a text file saying "Success -- or whatever".  I would like it to be an html file instead.  

Can you give me the "dummy code" that I can put in.  Or do I just cut and paste some HTML where the following goes?

print "mail sent succesfully.";

Thanks!

Rowby



0
 
LVL 1

Expert Comment

by:lambda
ID: 2662831
Yeah, sure.
One method of doing it is, putting your entire HTML code where you have "mail sent succesfully". Like this:

print <<END_HTML
<html>
<head>
<title>Mail sent</title>
<body>
<h2>Mail sent succesfully...!!</h2>
</body>
</html>

END_HTML

Replace the line
print "mail sent succesfully.";

with the above code.

Another way of doing it is placing the original HTML file some where in the server, say, "/usr/file/success_msg.html"
and read it & print it as follows:

open (HTML_FILE, "/usr/file/success_msg.html") || die "cant open the html file";
@Success_Html = <HTML_FILE>;
close(HTML_FILE);

foreach (@Success_Html)
{
  print $_;
}

Okay?
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2663059
Hmmm...

First of all, should we move this addition to the original question to another Experts Exchange question so I can award you the points?

Next, with the modifications on the bottom of this comment I got an an internal server error.

I telneted to the errro_logs and received:
[client 216.244.1.177] Premature end of script headers: /web/guide/mdsutton/cgibin/email_articles/email-article.cgi

Here is a cut an paste of the entire script:
#! /usr/local/bin/perl
use CGI;

$q=new CGI;
$friendname=$q->param("friend_name");
$friendmail=$q->param("friend_mail");
$sendername=$q->param("sender_name");
$sendermail=$q->param("sender_mail");
$articlename = "I asked M.D. Sutton to send you this Informative article";

#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
while (<FILE>)
{
  $articlebody .= $_;
}
close (FILE);

$mail_program = "/usr/sbin/sendmail -t";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;
close (MAIL);

print "Content-type: text/html\n\n";
print <<END_HTML
<body background="http://www.mdsutton.com/images/line-bg1.gif">

<CENTER>
<TABLE WIDTH="510" BORDER="0" CELLPADDING="3" BGCOLOR="#FFFFFF">
</table>
</center>
<div align="center">
  <center>
  <table>

 <TR>
 <TD>
  <TABLE WIDTH="637" BORDER="0" CELLPADDING="5" BGCOLOR="#FFFFFF">
   <TR>
    <TD width="520">
      <CENTER>
      <FONT FACE="ARIAL">
      <font color="#800000" size="4" face="ARIAL"><b>
      &nbsp; Thank you!&nbsp; &nbsp;</b></font>
      <B><font color="#000080"><br>
      Your email was sent to the address given on the form. <br>
      Click&nbsp; below to return to the website.<br>
      </font><font color="#800000">
      <BR>
      </font>
      <map name="FPMap2">
<area href="http://www.mdsutton.com/index.html" shape="rect" coords="11, 10, 74, 35">
<area href="http://www.mdsutton.com/contactus.htm" shape="rect" coords="83, 14, 177, 31">
<area href="http://www.mdsutton.com/our_products.html" coords="187, 9, 268, 35" shape="rect">
<area href="http://www.mdsutton.com/infocentral/info-central.html" shape="rect" coords="275, 11, 372, 35">
<area href="http://www.mdsutton.com/aboutmdsutton/about-mdsutton.html" shape="rect" coords="382, 9, 533, 35"></map><img border="0" src="http://www.mdsutton.com./images/bottom-navbar-march21.gif" usemap="#FPMap2" width="542" height="42">
    </TD>
    <TD width="117" valign="middle">
      <FONT FACE="ARIAL">
     
<img border="0" src="http://www.mdsutton.com/images/mike-with-name.gif" align="left" width="106" height="140">
    </TD>
   </TR>
  </TABLE>
  </TD>
 </TR>
    </table>
   </center>
  </div>

END_HTML  
0
 
LVL 1

Expert Comment

by:lambda
ID: 2663141
>First of all, should we move this addition to the original question to another Experts Exchange question so I can award you the points?

No need, I only want to answer ur questions, 'cos I am learning too!

>Next, with the modifications on the bottom of this comment I got an an internal server error.

That was my mistake. Do add a semi colon at the end, in one line by itself.
Like this:

</TR>
    </table>
   </center>
  </div>

END_HTML  
;

Do try this and let me know.
I think I am missing some mails from EE too. I didn't see your earlier comment till I accidentally dropped in this way.
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2664934
Nope.  Here's a cut and paste of the end of the script as I modified it

 </TR>
    </table>
   </center>
  </div>

END_HTML  
;

telnet error message:
[Tue Mar 28 12:18:15 2000] [error] [client 209.179.245.221] Premature end of scr
ipt headers: /web/guide/mdsutton/cgibin/email_articles/email-article.cgi

===
Could it be the various quotes within the html that are causing a problem

ROwby

0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2665027
I went ahead and used your other version.  The version where the HTML file was located elsewhere and...

IT WORKED!

I am going to close this by awarding lmbda the 200 points.

But I am going to open another question in the CGI area for one more refinement on this script that I would like on this form.

And for that I'll award you 250 points, and I'm sure you will have the answer.

Thanks,


Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2665032
Oops, I meant I am awarding this to venky  (hard to keep these nicknames straight!)

THanks venky!  

And Lambda, please look for my refinement question that I'll be posting in a few minutes.

Rowby
0
 
LVL 9

Author Comment

by:Rowby Goren
ID: 2667525
I guess you all know there has been some kind of server error on Experts Exchange.  I tried to award the points several times, and got a bad page, server error etc.

But I assume it's all been fixed.  There is now no place on this form for me to award the points.  But I think they have been awarded.

I also posted a follow up question here which kept disappearing over the last couple of days.  It's for Lambda -- After I submit this I'll see if that follow up still exists. If not, I'll re-do it!

Thanks again.
0
 
LVL 1

Expert Comment

by:lambda
ID: 2668401
The error with the earlier code could have been the line

print <<END_HTML

which should have read,
print <<END_HTML;

Must be... I haven't tried anyway. Glad to know you solved it using the other method. I read your last comments only just now.

Best Regards,
lambda.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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.

759 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

19 Experts available now in Live!

Get 1:1 Help Now