Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI scripting - email 6

Status
Not open for further replies.

JennyW

Technical User
Mar 1, 2001
323
CA
Hieee!

I was wondering if someone could direct me to some good help.

I want to use a ‘lil CGI scripting on my webpage.
Actually, all I want to do is have a button where people can submit their email address to me.

Is this difficult to do?
Where can I get straight-forward info. on how to do this?

Thanks so much for reading!
Jenny
 
I am sure that there are many posts in this forum on how to do so. You also might want to check the CGI forum on how to do so.

The vocabulary to sending email with Perl is called 'piping', wherein you open a pipe (|) to another program, in this case, the mail program, and do something with it.

If you are on a Unix/Linux machine, you will most likely use sendmail. I can not say the same for Windows because I am not sure.

A few sites:


I think that those will get you started in the right direction. I suggest picking up a book on CGI scripting, it sure to help you on this matter.

Hope this helps

-Vic vic cherubini
vikter@epicsoftware.com
====
Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director
====
 
The ActiveState Perl distribution ( has documentation that talks about sending email from a CGI script on a Windows machine. You need the Net::SMTP module, and there are code samples.

Of course, the *nix solution is much easier, but many of us don't have the luxury of working on those machines.
 
I think you're making this more complicated that you need. All she wants to do is have them submit an email address to her. Doesn't say anything about automatically sending email back. A simple form with an email action should be sufficient to get the email addresses entered sent to her.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hey all!
tsdragon.
I'm kinda stuck though, like how do I do this?
I set up a form on my site and when I click on submit my email program opens up with my email address in the address bar.

What am I doing wrong?

Please help.
Thanks,
Jenny
 
Try something like this:
Code:
<FORM METHOD=&quot;POST&quot; ACTION=&quot;MAILTO:name@company.com&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;Name&quot; SIZE=&quot;30&quot; MAXLENGTH=&quot;30&quot; >
<INPUT TYPE=&quot;text&quot; NAME=&quot;Email&quot; SIZE=&quot;30&quot; MAXLENGTH=&quot;30&quot; >
<TEXTAREA NAME=&quot;Message&quot; ROWS=&quot;5&quot; COLS=&quot;30&quot; ></TEXTAREA>
<INPUT TYPE=&quot;reset&quot; VALUE=&quot;Reset&quot;>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;Submit&quot; VALUE=&quot;Submit&quot;>
</FORM>
I haven't used this type of form submission, but it should email the form fields to the email address after MAILTO: when the form is submitted.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Hi all,
tsdragon, I made a page with your script (above) and I received this Windows message...

&quot;This form is being submitted using email.
Submitting this form will reveal your email address to the recipient, and will send the form data without encrypting it for privacy.
You may continue or cancel this submission.&quot;

If I pick continue, Outlook Express opens. However, it doesn't open with the message I wrote in the Form. It just opens with my email address inserted in the address bar.

Thanks,
Jenny
 
Jenny, I like tsdragon's suggestion, but instead of having

ACTION=&quot;MAILTO:name@company.com&quot;

just take that whole ACTION statement out, and the form will post back into itself(the same cgi script), and you will be able to retrieve the email address typed in by looking at the &quot;Email&quot; post variable. I'm most familiar with getting the POST variables by way of CGI.pm, like this:

use CGI qw:)standard);
my $q = new CGI;
$email = $q->param(&quot;Email&quot;);

but there are other ways too - whatever you're most comfortable with for retrieving POST/GET/Cookie variables.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Hi,
hmerrill, I don't if it makes sense to take out the...

ACTION=&quot;MAILTO:name@company.com&quot;

..script, because I'm trying to make this form work without CGI scripting.

All I wanna do get people to send me their email addresses so I can put them on my mailing list.

Thanks,
Jenny
 
Hi tsdragon and others,

Here's the url with tsdragon's Form code implemented...


It doesn't send the info. entered to the specified email address.
Instead, it opens the users email program and inserts my email address in the address bar. The info. the user entered in the Form is not put in the email.

Thanks,
Jenny
 
Hi Mr. Danger,

Yeah! I've been looking for those kind of programs. I found an old one (URLcook) but the download didn't work. I will give a shot to the two you listed.

Thanks so much!
Jenny
 
Jenny,
Is this what you are trying to do. This HTML anchor tag will pop an email client window that is already addressed to you with a preset subject and what ever you want in the body.

Code:
<HTML><HEAD><TITLE></TITLE></HEAD>
<BODY><P>
<a href='mailto:jennyW@someserver.com?
	subject=another email address sent to jennyW&
	body=Please type your email address: '>
	send an email</a>
</P>
</BODY>
</HTML>
</HTML>

This will work with later versions Netscape and IE and I expect many other browsers that have email clients associated with them.

HTH


keep the rudder amid ship and beware the odd typo
 
Hi,
No, I’m not looking for the users email program to open.
If the visitor only has a hotmail email address then opening their systems email program won’t do me or them any good.
All I want is for website readers to fill out a form inserting their email address. I want the info. they enter in the Form to be sent to my email address so I can add them to a mailing list.

Thanks,
Jenny
 
Jenny,

I tried the from I posted above (substituting my email address in the MAILTO:) and it worked without opening outlook, although it did give me the message you quoted. If you want to do this without the message you can have a simple cgi script just email you the contents of the form. I think I have one that will do that filed away somewhere. I'll look for it this afternoon and post it if I can find it.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Instead of using an e-mal client to send the e-mail address, would it make sense to have the form write its data to a file on the server.
Basically append to a file. Then you could just read the file for its contents. Safe and easy

Seems pretty easy (or did I miss the point)

-Danny






 
Here is a fairly simple program that will just &quot;decode&quot; and email the names and values of fields on a form and redirect the user to another page:
Code:
#!/usr/local/bin/perl

# MailForm.pl - Email form data

# Substiture your own values here!
$MailCmd = &quot;/usr/lib/sendmail -t&quot;;	# Your email program command
$ToAddr = &quot;tracy\@bydisn.com&quot;;		# Your email address
$FromAddr = &quot;tracy\@bydisn.com&quot;;	# From email address
$Subject = &quot;Test MailForm.pl&quot;;		# Email subject
$ResultsPage = &quot;[URL unfurl="true"]http://www.bydisn.com/Results.html&quot;;[/URL] # Page to redirect to when done
# End user values

# Flush stdout
$| = 1;

# Get the form data
if ( $ENV{&quot;REQUEST_METHOD&quot;} eq &quot;GET&quot; ) {
	$FormData = $ENV{&quot;QUERY_STRING&quot;};
} elsif ( $ENV{&quot;REQUEST_METHOD&quot;} eq &quot;POST&quot; ) {
	read(STDIN, $FormData, $ENV{&quot;CONTENT_LENGTH&quot;});
} else {
	print &quot;Content-type: text/html\n\n&quot;;
	print qq[<html><head></head><body><h2>Invalid Form Method: $ENV{&quot;REQUEST_METHOD&quot;}</h2></body></html>];
}

# Split data into list (array) of key=value entries
@FormData = split(/&/, $FormData);

# Process the FormData list
foreach $x (0 .. $#FormData) {
	# Convert plus signs back to spaces
	$FormData[$x] =~ s/\+/ /g;

	# Split into key and value (on the first equal sign found).
	($key, $val) = split(/=/, $FormData[$x], 2);
	
	# Convert %XX sequences into characters
	$key =~ s/%(..)/pack(&quot;c&quot;, hex($1))/ge;
	$val =~ s/%(..)/pack(&quot;c&quot;, hex($1))/ge;
	
	# Replace list element with converted values
	$FormData[$x] = $key . &quot;=&quot; . $val;

	# Create associative array member
	# Null value ('\0') separates multiple values
	$FormData{$key} .= &quot;\0&quot; if (defined($FormData{$key}));
	$FormData{$key} .= $val;
}

# Open email pipe
open(MAIL, &quot;| &quot;.$MailCmd);

# Print headers
print MAIL &quot;To: $ToAddr\n&quot;;
print MAIL &quot;From: $FromAddr\n&quot;;
print MAIL &quot;Subject: $Subject\n&quot;;
print MAIL &quot;\n&quot;;

# Print form variables
foreach my $key (keys %FormData) {
	print MAIL &quot;$key: $FormData{$key}\n&quot;;
}

# Close email pipe
close(MAIL);

# Redirect to results page
print &quot;Location: $ResultsPage\n\n&quot;;

exit 0;
1;
You need to substitute your own values into the top section where indicated.

Here is a sample form that calls it:
Code:
<HTML>
<HEAD>
<TITLE>Test MailForm.pl</TITLE>
</HEAD>
<BODY>
<div align=&quot;center&quot;>
<h2>Test MailForm.pl</h2>
<form name=&quot;test&quot; method=&quot;post&quot; action=&quot;/cgi-local/MailForm.pl&quot;>
<table>
<tr><td>Name:</td><td><input type=&quot;text&quot; name=&quot;name&quot;></td></tr>
<tr><td>Email Address:</td><td><input type=&quot;text&quot; name=&quot;email&quot;></td></tr>
<tr><td colspan=&quot;2&quot; align=&quot;center&quot;><input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit&quot;></td></tr>
</table>
</form>
</div>
</BODY>
</HTML>

And here is a sample redirect page (Results.html):
Code:
<HTML>
<HEAD>
<TITLE>Thank You</TITLE>
</HEAD>
<BODY>
<h2>Thanks for sending me your email address</h2>
</BODY>
</HTML>

This is an example of what the email from the above will look like:
Code:
To: tracy@bydisn.com
From: tracy@bydisn.com
Subject: Test MailForm.pl

email: tracy@bydisn.com
name: Tracy Dryden
submit: Submit

You can try it out at:
(NOTE: The above link will send the email to the email address entered on the form instead of to me, so you can see what the results look like). Be patient, our ISP (RapidSite) mail server seems to be a REAL slow.
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top