943,097 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1318
  • Perl RSS
Feb 3rd, 2010
0

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

Expand Post »
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.
Perl Syntax (Toggle Plain Text)
  1. #!C:/Perl/bin/Perl.exe
  2.  
  3. use strict;
  4. use CGI qw(:standard);
  5. use CGI;
  6. use check;
  7. my $q = new CGI;
  8.  
  9.  
  10.  
  11. print $q->header("text/html");
  12. my $action = param("action");
  13. print button();
  14.  
  15. sub button {
  16. return <<EOF;
  17. <html>
  18.  
  19. <head>
  20. <title></title>
  21. </head>
  22.  
  23. <body bgcolor="#95CBE9">
  24.  
  25. <form>
  26.  
  27. <TABLE BORDER=0 align="center" cellpadding="20">
  28. <TR>
  29. <TD>User Name</TD>
  30. <TD>
  31. <INPUT type=text size="40" name="username" value=""/>
  32. </TD>
  33. </TR>
  34. <TR>
  35. </TR>
  36. </TABLE>
  37. <br><br><br>
  38.  
  39. <p>
  40. <center>
  41. <input type="submit" value="Submit" onClick=?????>
  42. </p>
  43. </form>
  44.  
  45. </body>
  46. </html>
  47. EOF
  48. }

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:MTP
Perl Syntax (Toggle Plain Text)
  1. use Net::SMTP;
  2. my $smtpserver = 'xxx.xxx.xxx.xxx';
  3. my $smtpuser = 'username';
  4. my $fromemail = 'someone@somewhere.com';
  5.  
  6. my $smtp = Net::SMTP-> new($smtpserver, Timeout => 10);
  7. $smtp-> mail($smtpuser);
  8. $smtp-> to('someoneelse@somewhere.cz');
  9. $smtp-> data();
  10. $smtp-> datasend("To: blblb\@blblbl.cz\n");
  11. $smtp-> datasend("From: psmejkal\@tesco.cz\n");
  12. $smtp-> datasend("\n");
  13. $smtp-> datasend("test\n");
  14. $smtp-> dataend();
  15. $smtp-> quit;

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

Any help would be really appreciated.

~Rose
Reputation Points: 3
Solved Threads: 0
Newbie Poster
navarannan is offline Offline
12 posts
since Jul 2009
Mar 11th, 2010
0

Better be late than never...

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~
Reputation Points: 11
Solved Threads: 0
Newbie Poster
rdxblast is offline Offline
16 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: pattern matching
Next Thread in Perl Forum Timeline: page redirction in perl





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC