Forms to email

G

Gordon

Hi...

Ouch - I'm stumped!

I use forms to email on lots of my sites - all of which run on Unix servers.
There seem to be lots of easy and free scripts available.

I have a new site running on Widows 2000 servers and simply can't find a
script that works.

I'm presently trying to use a .pl script, which the ISP in question
provided, but which only sends the contents of a single message field.

I need to have separate fields for Name, Address, email, phone, and message,
all to be sent in the email.

Does anyone know how to add to the .pl script below the instructions to send
the other fields as well.

Any help appreciated...

Gordon





# Use the cgi module.
use cgi;

# Get values from sample form.
$form = new CGI;

# This is the name of the person sending the email.
$sender = $form->param('sender');

# This is the address the email is being sent from.
# This must be a valid domain hosted on the server.
$from = $form->param('from');

# This is the name of the recipient of the email.
$recipient = $form->param('recipient');

# This is the email address that the message should be sent to.
$to = $form->param('to');

# This is the subject header for the email.
$subject = $form->param('subject');

# This is the address of the SMTP server to use to send the email.
$smtp = "mail.newnet.co.uk";

# This is the email message.
$message = $form->param('message');

$lt='<';
$gt='>';

# Save the message into a text file.
open (messtxt,">message.txt");
print messtxt ($message);
close messtxt;

# Build the Blat command line.
# $blat="blat.exe message.txt -s \"$subject\" -t
\"$lt$to$gt$recipient\" -server $smtp -f \"$lt$from$gt$sender\"";
$blat="blat.exe message.txt -s \"$subject\" -t \"$to\" -server $smtp -f
\"$from\"";

# Execute the command to send the email.
system($blat);

# Command to redirect the user to another webpage.
# Change the url below to the url of the page you wish to redirect to.
$redirect = "http://www.mydomain.com";

print "Content-type: text/html\n\n";
print "<HTML><HEAD>";
print "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=$redirect\">";
print "</HEAD><BODY>";

# Uncomment the lines below to display the mail sent message in the browser.
# print $blat;
# print "<br><br>Done.<br><br>";
# print "Mail sent to $to.";

print "</BODY></HTML>";
 
R

Ronx

Set up a loop to go through all the fields in the $form->param hash and add
to the $message variable
See inline below

HTH
Ron
--
Reply only to group - all emails will be deleted unread.


Gordon said:
Hi...

Ouch - I'm stumped!

I use forms to email on lots of my sites - all of which run on Unix servers.
There seem to be lots of easy and free scripts available.

I have a new site running on Widows 2000 servers and simply can't find a
script that works.

I'm presently trying to use a .pl script, which the ISP in question
provided, but which only sends the contents of a single message field.

I need to have separate fields for Name, Address, email, phone, and message,
all to be sent in the email.

Does anyone know how to add to the .pl script below the instructions to send
the other fields as well.

Any help appreciated...

Gordon





# Use the cgi module.
use cgi;

# Get values from sample form.
$form = new CGI;

# This is the name of the person sending the email.
$sender = $form->param('sender');

# This is the address the email is being sent from.
# This must be a valid domain hosted on the server.
$from = $form->param('from');

# This is the name of the recipient of the email.
$recipient = $form->param('recipient');

# This is the email address that the message should be sent to.
$to = $form->param('to');

# This is the subject header for the email.
$subject = $form->param('subject');

# This is the address of the SMTP server to use to send the email.
$smtp = "mail.newnet.co.uk";

# This is the email message.

Change script from here---

# initialise $message
$message = "";
# This is the email message, including all other fields
# set up a loop to go through the form fields
foreach my $test ( $form->param ) {


# if field already dealt with above, goto next field
next if $test =~ /^to|from|subject|recipient|sender/;


# ensure field has some data
if (defined( $form->param( $test ) )) {

# add field name and value
$message .= $test."\n";
$message . = $form->param( $test )."\n\n";
}
#close loop
}

remove this line
 
G

Gordon

Jim Buyens said:
Change the statement
$message = $form->param('message');
to store whatever content you want in the $message
variable. For example:

$message = "You said: " + $form->param('message') +
"\nand also: " + $form->param('moremsg') +
"\nbut not: " + $form->param('whatever');

where message, moremsg, and whatever are the names of form
field elements.



I've made it read:

$message = "You said: " + $form->param('message') +
"\nand also: " + $form->param('sender') +
"\nand also: " + $form->param('from') +
"\nand also: " + $form->param('telephone') +
"\nand also: " + $form->param('address');

and amazingly get an email reading "30". That's all.

Any more thoughts? My test page is at
http://www.create-space.com/cgi-bin/form/formtomail.html

Thanks,

Gordon
 
R

Ronx

You haven't provided a method for your form
<form action="formmail.pl" method="post">
This might make a difference.
If you change the script to print out on the confirmation page what has been
received by the form it will make debugging easier.
See www.rxs-enterprises.com/rxsents/formmail.htm as an example
(use test#1 as the subject, then no emails will be sent)

HTH
Ron
PS Being able to edit the script will enable you to hard code your email
address into it, and thus hide from spam-bots...
 
G

Gordon

Hi, and thanks to you both.

Changing the method doesn't make any difference unfortunately.

My test is now at
http://www.create-space.com/cgi-bin/testform/formtomail.html , and still
simply sends a single numeral, whatever the field input.

My trouble here is that I'm in way above my knowledge level, and don't
really know what I'm doing - extreme old age blunting the senses...

There must be a way of making this thing work!

Gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top