• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 412
  • Last Modified:

sendmail module using formmail

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
tinybear
Asked:
tinybear
  • 7
  • 5
2 Solutions
 
PeeweeCommented:
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
 
PeeweeCommented:
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
 
tinybearAuthor Commented:
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
PeeweeCommented:
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
 
tinybearAuthor Commented:
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
 
PeeweeCommented:
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
 
tinybearAuthor Commented:
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
 
PeeweeCommented:
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
 
tinybearAuthor Commented:
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
 
TintinCommented:
Just head over to http://nms-cgi.sourceforge.net/ and install FormMail.  This will take care of what you need.
0
 
PeeweeCommented:
tinybear,
any joy yet, do u need further help?

Peewee
0
 
PeeweeCommented:
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
 
tinybearAuthor Commented:
Ive asked for the points to be realocated to you.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now