Solved

sendmail module using formmail

Posted on 2004-08-24
15
385 Views
Last Modified: 2013-12-25
Hi,

I have a form on a secure server which when submitted i want to send a cinfirmation email to the user. The secure server does not have php but the ISP has told me I can use the sendmail module using formmail.

The path to this is (supplied by the ISp)


/usr/sbin/sendmail .


So can anyone give me an example in HTML of how to get this working as the ISp have been of no help.

Basically I want to just send an email to an address entered by the user..saying eg thank you for your submission. with a reply address of my domain and sbjet of e.g Thank you for your enquiry.

The reason this is on a secue server is there is other data on the form I want kept confidential.

0
Comment
Question by:tinybear
  • 7
  • 5
15 Comments
 
LVL 5

Expert Comment

by:Peewee
ID: 11890241
tinybear,

this code should help you:

#!/usr/bin/perl
use CGI;

my $query    = new CGI;
my $sendmail = "/usr/sbin/sendmail -t";
my $reply_to = "Reply-to: foo@bar.org";
my $subject  = "Subject: Confirmation of your submission";
my $content  = "Thanks for your submission.";
my $to       = $query->param('send_to');
my $file     = "subscribers.txt";

unless ($to) {
  print $query->header;
  print "Please fill in your email and try again";
}

open (FILE, ">>$file") or die "Cannot open $file: $!";
print $to,"\n";
close(FILE);

my $send_to  = "To: ".$query->param('send_to');

open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);

print $query->header;
print "Confirmation of your submission will be emailed to you.";
0
 
LVL 5

Expert Comment

by:Peewee
ID: 11890287
tinybear,
also MIME::Lite is a nice module to use assuming you have it installed:

http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm

regards Peewee
0
 

Author Comment

by:tinybear
ID: 11890390
Peewee,

so Do do I corporate this into my HTML form file? Do I call the file .htm

I have the email address already stored in a cookie which can be loded into a from field . or easier if it could be read directly into the $to variable

Also what goes in the subscribers.txt file?

Sorry but this is very new to me. so have been thrown in at deepend really.





0
 
LVL 5

Expert Comment

by:Peewee
ID: 11890694
Hi tinybear,

my example gets the input parameters, ie email address etc from a html form.  If yours is different you'll need to ammend the code snippet to suit your purposes.

The subscribers.txt was for my purposes, just to store a list of email addresses, i removed this as you may not need it.   I've also changed the $to var to get the email address from a cookie value, you will need to replace (key) $cookies{'key'}->value; with your cookie name.

let me know how you get on..

Peewee

#!/usr/bin/perl
use CGI;
                                                                                                                                                             
my $query    = new CGI;
my $sendmail = "/usr/sbin/sendmail -t";
my $reply_to = "Reply-to: foo@bar.org";
my $subject  = "Subject: Confirmation of your submission";
my $content  = "Thanks for your submission.";
#my $to       = $query->param('send_to');
                                                                                                                                                             
my %cookies  = fetch CGI::Cookie;
my $to = $cookies{'key'}->value;
                                                                                                                                                             
                                                                                                                                                             
                                                                                                                                                             
unless ($to) {
  print $query->header;
  print "Please fill in your email and try again";
}
                                                                                                                                                             
my $send_to  = "To: ".$query->param('send_to');
                                                                                                                                                             
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
                                                                                                                                                             
print $query->header;
print "Confirmation of your submission will be emailed to you.";



0
 

Author Comment

by:tinybear
ID: 11890754
ok. a bit clearer. still a few questions tho'

so I save this as a cgi file? In Same dir as the html? Also presume I will have to chmod the file to allow execute.


how do I call it from the html.

do I use GET or POST as the method.

Very helpful up to now

0
 
LVL 5

Accepted Solution

by:
Peewee earned 250 total points
ID: 11890847
Hi tinybear,

save the perl script as mail.cgi within the cgi-bin designated by your web server.
chmod 775 mail.cgi
run a perl -c mail.cgi on the command line if you can to check for syntax errors.

how do I call it from the html.
Here's an exmaple:

<FORM method="POST" action="/cgi-bin/mail.cgi">
<INPUT type="text" name="send_to">
etc => enter your input types here
etc
etc
<INPUT type="submit">
</FORM>


do I use GET or POST as the method.

either is fine..


then submit the form and see what happens..

Peewee

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:tinybear
ID: 11890870
Peewee,

that will be a problem as I am only allowed to save filles in one dir on the secur server. dont have access to any other dirs.

0
 
LVL 5

Expert Comment

by:Peewee
ID: 11890959
Tinybear,
a cgi file will typically execute only where the web server configuration allows it.   Your ISP will have configured somewhere for you to run your scripts, this is the norm, and normally this is under a directory called cgi-bin, check with your ISP if you are configured for CGI, i'm assuming you are from your initial post.

The Html files are similar, the web server will also be configured to run these from a particular location, again check with your ISP..
Check your directory names, there normally the give away, and sometimes they leave example scripts in your directories aswell.

Who'se your ISP, and when you log in do you have command line access, or ftp access?  When you do log into what directories can you immediately see?


Peewee


Peewee
0
 

Author Comment

by:tinybear
ID: 11891019
ISp is MyServerWorld through Pipex. The secure space is provided to them by www.secure-website.com


The secure space is a shared secure space and I only see one dir when I log into the file manager through the control panel.

The main webspace which is not secure is fine, I have cgi-bin access. and can ftp to any dir. but not the secured order space.

I have just looked and it seems that I may be able to use thecgi-bin dir on my main webspace. The secure-website is just a generic name m they use to hide the MyServerworld info from being seen in the URL.
so it may be possible I am going to look into it..

 

0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 250 total points
ID: 11899043
Just head over to http://nms-cgi.sourceforge.net/ and install FormMail.  This will take care of what you need.
0
 
LVL 5

Expert Comment

by:Peewee
ID: 11988138
tinybear,
any joy yet, do u need further help?

Peewee
0
 
LVL 5

Expert Comment

by:Peewee
ID: 12198338
TheLearnedOne,
i think i've answered his question single handed. I've provided working cgi & html code in five different posts which Tinybear has responded to; he hasn't responded to anyone else.  I would therefore suggest the points are mine..

Peewee
0
 

Author Comment

by:tinybear
ID: 12198459
Ive asked for the points to be realocated to you.

0

Featured Post

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.

Join & Write a Comment

It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 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

18 Experts available now in Live!

Get 1:1 Help Now