Please Need help grabbing 2 variables - cgi

Posted by Topache on Tue 26 Apr 2005 12:49 AM — 3 posts, 19,418 views.

#0
Hi,

Please I need your help.

I'm trying to make something out of a cgi form mail script.

I have everything workiing so far except for 1 little detail that is giving me a headache.

What I'm trying to accomplish is to have a form someone can fill out where they type in the begining of an email address in 1 field (ex johndoe) then from a drop down list select the second part (ex @you.com or @me.com) then fill out the other 2 fields and be able to send that to the approciate place. (either johndoe@you.com or johndoe@me.com).

If you look at my script below you can see where I'm trying grab the begining and end of the email. It runs without any errors, but I don't get the email sent to me. If I totally remove the second half and actually type in johndoe@you.com in the 1st field it will send an email their. I just can't get my selection drop down to work.

Can anyone help PLEASE! and THANKYOU!!

Part of the html form:

</HEAD>
<BODY>
<form action="http://anywho.com/cgi-bin/text.cgi" method="post">
<table border="0">
<TR>
<TD COLSPAN="2">Please fill in the details below to send us a message</TD>
</TR>
<TR>
<TD colspan="2">&nbsp;</TD>
</TR>
<TR>
<TD align="left" width="20%"><B>Cell:</B></TD>
<TD><input type="text" name="first">
@<select name="second" size="1">
<option value="\@me.com" selected>Verizon</option>
<option value="@you.com">Cingular</option>
</select>
</TD>
</TR>
<TD align="left" width="20%"><B>Name:</B></TD>
<TD><input type="text" name="fname"></TD>
</TR>
<TR>
<TD align="left" width="20%"><b>Email Address:</b></TD>
<TD><input type="text" name="email_add"></TD>
</TR>
<TR><TD ALIGN=left valign="top" width="20%"><b>Message:</b></TD>
<TD><textarea name="email_msg" rows="20" cols="30"></textarea></TD>
</TR>
<TR>
<TD colspan="2">&nbsp;</TD></TR>
<TR><TD colspan="2"><center><INPUT TYPE="submit" VALUE="Send Message"></center></TD>
</TR>
</TABLE>
</form>

Part of the cgi:

#!/usr/bin/perl

use strict;

use CGI;

my $cgiobject = new CGI;

my $fname=$cgiobject->param("fname");
my $email_add=$cgiobject->param("email_add");
my $email_msg=$cgiobject->param("email_msg");
my $MailProgram = '/usr/lib/sendmail';
my $cell =$cgiobject->param("cell","where");

print "Content-type: text/html\n\n";

open (MAIL,"|$MailProgram -t") || &errormess;
print MAIL "To: $cell\n";
print MAIL "From: $email_add\n";
print MAIL "Reply-to: $email_add\n";
print MAIL "Subject: Email From Your Website\n";
print MAIL "Name $fname\n";
print MAIL "email $email_add\n";
print MAIL "Msg $email_msg\n";
close(MAIL);

#1
Dis-regard the Part of the cgi from above. THIS IS THE CORRRECT ONE.. sorry about that.


Part of the cgi:

#!/usr/bin/perl

use strict;

use CGI;

my $cgiobject = new CGI;

my $fname=$cgiobject->param("fname");
my $email_add=$cgiobject->param("email_add");
my $email_msg=$cgiobject->param("email_msg");
my $MailProgram = '/usr/lib/sendmail';
my $first =$cgiobject->param("first","second");

print "Content-type: text/html\n\n";

open (MAIL,"|$MailProgram -t") || &errormess;
print MAIL "To: $first\n";
print MAIL "From: $email_add\n";
print MAIL "Reply-to: $email_add\n";
print MAIL "Subject: Email From Your Website\n";
print MAIL "Name $fname\n";
print MAIL "email $email_add\n";
print MAIL "Msg $email_msg\n";
close(MAIL);
USA #2
Disregarding the fact that this is NOT a perl forum (pay more attention to your forums next time, if nothing else, this should have been posted in Programming > General, and it still doesn't fit) but a forum for Perlscripting within Mushclient (a Mud client).

$cgiobject->param("first","second") sets the parameter first to the string "second".
It does NOT return both appended to each other.
So this whole time you've been sending email (or trying) to the "second" email address.
And, you need to make sure you escape BOTH your @'s.

You can (and probably should) read more about CGI.pm here:
http://users.easystreet.com/ovid/cgi_course/appendices/appendix3.html#fetching%20the%20value%20or%20values%20of%20a%20single%20named%20parameter:

And then the header halfway down the page explains what your current code does.