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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Msg to email *Help!* 1

Status
Not open for further replies.

benzito

ISP
Jan 8, 2002
144
US
I'm fairly new to java and am stuck on executing the fwg code. ANY help @ all greatly appreciated.

Send contents of msg box to certain email address(es). Email address is dependent on which product is selected from drop down box

ie.
-----------------------------------
If product = a then send email to x
If product = b then send email to y
 
show me the script you have written thus far and i will do my best to help you
 
Just a tip: I don't suggest using client-side JavaScript, since the method to do it would be to replace the page's address to a mailto: address. This would launch the client's default mail client. It would be very inconvenient and still depend on the user to send it anyway.

Unless you're planning on using server-side JavaScript, I strongly recommend keeping away from attempting to use JavaScript to send e-mails.

And here's a little something: Java != JavaScript
bluebrain.gif
blueuniment.gif
 
Thanx everyone, here's the code in php, unfortunately the server I have to work w/ doesn't support it. I thought there might be a solution avail w/ java? asp maybe? Any suggestions appreciated.

<?
if(!$submit){
?>

<form action=&quot;<? echo $PHP_SELF ?>&quot; method=&quot;post&quot;>

Select Product:
<select name=&quot;what&quot;>
<option>---
<option>Product A
<option>Product B
</select>

<br>

From:
<input name=&quot;from&quot;><br>

Subject:
<input name=&quot;subject&quot;><br><br>
Message:<br>
<textarea name=&quot;message&quot; rows=&quot;8&quot; cols=&quot;30&quot;>
 

see if your server supports cgi's...if so, this can be easily done...more than likely, they do...so repost, if so and i'll post a cgi for mail. it's simple and easy to use.


- spewn
 
here goes...


here is the form page:

index.html
**

<body>
<form action='sendmail.cgi'>
<br><br>
enter your email address
<br>
<input type=text name=eml>
<br><br>
what is the subject?
<br>
<input type=text name=sbj>
<br><br>
what would you like to say?
<br>
<textarea name=msg rows=3 cols=30></textarea>
<br><br>
<input type=submit value='send mail'>
</form>
</body>

**


here is the cgi:

sendmail.cgi:
**

#!/usr/local/bin/perl

%postInputs = readPostInput();
$dateCommand = &quot;date&quot;;
$time = `$dateCommand`;
open (MAIL, &quot;|/var/qmail/bin/qmail-inject&quot;) || return 0;

select (MAIL);
print << &quot;EOF&quot;;

To: test\@one-degree.com
From: $postInputs{'eml'}
Subject: $postInputs{'sbj'}

$time
Comments: $postInputs{'msg'}

<b>test</b>

EOF
close(MAIL);
select (STDOUT);
printThankYou();

sub readPostInput(){

my (%searchField, $buffer, $pair, @pairs);
if ($ENV{'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'} );
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(&quot;C&quot;, hex($1))/eg;
$searchField{ $name} = $value;

}
}

return (%searchField);

}

sub printThankYou(){
print << &quot;EOF&quot;;
Location:
EOF
}

**


and finally here is the thank you page:

thankyou.html
**


<body>
<br><br>
thank you. you message has be sent.

</body>

**


to check it out in action, go here...


hope that helps...

my suggestion is if you have questions from this point, try the cgi forum...very helpful...


- spewn
 

hey, i messed up...don't know why it was in there, but...

**

<b>test</b> //delete this line, (sendmail.cgi)


**

my bad.


- spewn
 
Thx Spewn. works suh-weet. I know how to add the code for a drop down box but how would I make the drop-menu form element determine who the email will be routed to once the &quot;Submit&quot; button has been clicked?

Is it possible to make the drop-menu menu element determine who the email will be routed to once the &quot;Submit&quot; button has been clicked? I'll re-post in cgi too.

Drop down menu selection Result
-----------------------------------------------------------
If product = a then send email to x@x.net
If product = b then send email to y@y.net
 

also in the form tag, add:

method=&quot;POST&quot;

to read:

<form action='sendmail.cgi' method='post'>

cool...


- spewn
 
Cool but is there any way to make the code &quot;decide&quot; which email address to send the form to depending on input? (drop down box, check box, radio button....etc?)
 

yeah, give me a minute...

hey, did you test the cgi script through your server yet? (remember to change the receiving email to your own)

do it and tell me if you get an email...


- spewn
 
I tried it and a new page loads w/ the following:


'D:\Websites\vgsi\testbedfiles\cgi-bin\sendmail.cgi' script produced no output
 

are you through an isp server, or did you try and run it through your computer? i believe you have to run it from the server, the script doesn't work from my computer either...or perhaps you aren't directing to the perl at the top of the page correctly...(the # at the top of sendmail.cgi)


- spewn
 

oh yeah...also, you have to find out what the hosting provider uses for this line...

open (MAIL, &quot;|/var/qmail/bin/qmail-inject&quot;) || return 0;

mine is through hypermart, and that might be specific to them...

like another is...

open (MAIL, &quot;|/usr/sbin/sendmail -t&quot;) || return 0;

try finding that out, also...

honestly, the cgi forum will be much more useful...my cgi scope of knowledge, although growing, is still limited and as such, they might be of more service...

but give me a minute on the different email recipients...


- spewn
 
I'm on the same network as the web server <intranet> and I believe they use #!/usr/local/bin/perl as default. thx for the code, if you come up w/ the code for the multiple emails please post. I'm sure I can work w/ the cgi and pl, just ned to get w/ the web admin to access the server directly. For the time being I think I can accomplish what I need w/ some VERY heavy and ugly html :-(
 

the cgi is very functional...it's worth running by the cgi forum...they have more of an in depth understanding and have experienced many situations, so they would be able to help you further...

i'd be interested to see the 'heavy and ugly' html...


- spewn
 
Cool. I reposted in the cgi forum. I'll post the code for the html also. Starting it now...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top