Link to home
Start Free TrialLog in
Avatar of tinybear
tinybear

asked on

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.

Avatar of Peewee
Peewee

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.";
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
Avatar of tinybear

ASKER

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.





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.";



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

ASKER CERTIFIED SOLUTION
Avatar of Peewee
Peewee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.

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
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..

 

SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tinybear,
any joy yet, do u need further help?

Peewee
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
Ive asked for the points to be realocated to you.