954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Send Email using Perl when the Submit button is pressed, in Windows.

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>


<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

navarannan
Newbie Poster
12 posts since Jul 2009
Reputation Points: 3
Solved Threads: 0
 

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 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:

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~

rdxblast
Newbie Poster
16 posts since Mar 2010
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You