Hi Friends

I have a requirement to where my cgi program has to send an email when the "Submit" button is pressed.

Here is my cgi program, which has a text field to enter the username and a submit button.

#!C:/Perl/bin/Perl.exe

use strict;
use CGI qw(:standard);
use CGI;
use check;
my $q = new CGI;



print $q->header("text/html");
my $action = param("action");
print button();

sub button {
return <<EOF;
<html>

<head>
<title></title>
</head>

<body bgcolor="#95CBE9">

<form>

<TABLE BORDER=0 align="center" cellpadding="20">
<TR>
  <TD>User Name</TD>
<TD>
<INPUT type=text size="40" name="username" value=""/>
</TD>
</TR>
<TR>
</TR>
</TABLE>
<br><br><br>

<p>
<center>
<input type="submit" value="Submit" onClick=?????>
</p>
</form>

</body>
</html>
EOF
}

What I need to do is when the user hits the submit button an email has to be sent from Windows platform. I did a bit of googling and found out the perl script to send the mail as follows. This uses Net::SMTP

use Net::SMTP;
my $smtpserver = 'xxx.xxx.xxx.xxx';
my $smtpuser = 'username';
my $fromemail = 'someone@somewhere.com';

    my $smtp = Net::SMTP-> new($smtpserver, Timeout => 10);
    $smtp-> mail($smtpuser);
    $smtp-> to('someoneelse@somewhere.cz');
    $smtp-> data();
    $smtp-> datasend("To: blblb\@blblbl.cz\n");
    $smtp-> datasend("From: psmejkal\@tesco.cz\n");
    $smtp-> datasend("\n");
    $smtp-> datasend("test\n");
    $smtp-> dataend();
    $smtp-> quit;

But I have no idea on how to integrate it with the cgi script.

Any help would be really appreciated.

~Rose

Rose,

I am not sure whether you have the solution by now. Cos, you have posted few days back. Please ignore if you already have a solution...

Alright, as per your research you already have entire solution. All you require is integration.

The <form> tag in html has attributes which will do it for you. All you need to do is write a script which sends a email(as you have given a code snippet at the bottom) and glue the script in the form tag.

Like:

<form name="name_of_the_form" action="[page containing the script which triggers the mail]" method="[get or post]">

action attribute takes the page name which needs to be invoked when the user submit the form(i.e. when the user hits the 'submit'[or whatever name you give to the submit button] button.

In your case, you need to call the page which sends out the mail.

Thanks,
~RDX~

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.