Current location: Hot Scripts Forums » Programming Languages » Perl » maintaining the same email address in a form


maintaining the same email address in a form

Reply
  #1 (permalink)  
Old 11-26-07, 07:01 PM
cedric813 cedric813 is offline
Newbie Coder
 
Join Date: Jun 2007
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
maintaining the same email address in a form

Hi everyone,

I have this code below that will email the contents of a web page in HTML to a person of my choosing. Right now there are 2 fields to fill in: recipient's email address and sender's email address. Since the sender's email address (my email address) will always be the same, I would like to remove this field from the form and add something to the code so that it will automatically use my email address as the sender's email address when sending the email. The only field that I would like visable is the recipient's email address field. Can anyone help me please?

Thanks,
Cedric


perl Code:
  1. #!/usr/bin/perl
  2.  
  3. $scriptname = "MailPage";
  4. $version = "2.0";
  5.  
  6. use LWP::UserAgent;
  7. $ua = new LWP::UserAgent;
  8. $ua->agent("$ENV{'HTTP_USER_AGENT'}");
  9. use CGI::Carp qw(fatalsToBrowser); # Provides you with fatal error message if they occur.
  10. use CGI qw/:standard/;
  11. require 'mailpage.conf';
  12. require $mtvwebdesignlib;
  13.  
  14. main: {
  15. &getinput;
  16. &GetCookies;
  17.  
  18. if (lc $FORM{'action'} eq "send") { &getbase($FORM{'url'}); &send; }
  19. elsif (lc $FORM{'action'} eq "privacy") {&privacy;}
  20. else { &moreinfo }
  21.  
  22. }
  23.  
  24.  
  25. sub moreinfo {
  26. $FORM{'url'} = $ENV{'HTTP_REFERER'} unless $FORM{'url'};
  27. if ($FORM{'url'} !~ m/^http/ ) { $FORM{'url'} = $ENV{'HTTP_REFERER'}; }
  28.  
  29. print "Content-type: text/html\n\n";
  30. &pageheader("Email Hits");
  31. foreach $line (@temptoken) {
  32.     if ($line =~ m/$token/i) {
  33. <form action="$ENV{'SCRIPT_NAME'}" method="post">
  34. <input type="hidden" name="action" value="send">
  35. <input type="hidden" name="url" value="$FORM{'url'}">
  36. <TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 >
  37.     <TR>
  38.     <TD>Sender's Email address<input name="senderemail" value="$Cookies{'email'}"></TD>
  39.     </TR>
  40.     <TR>
  41.     <TD>Recipient's Email address<input type="text" name="recipientemail"></TD>
  42.     <td><INPUT TYPE="submit" VALUE="SEND"></td>
  43.     </TR>
  44.   </TABLE>
  45.   </BLOCKQUOTE>
  46. </form>
  47. ~;
  48.     }
  49. print "$line";
  50. }
  51. &powered_by("nologout");
  52. }
  53.  
  54. sub send {
  55.  
  56. &check_email($FORM{'senderemail'});
  57. &check_email($FORM{'recipientemail'});
  58.  
  59. &send_body;
  60.  
  61. &SetCookies("email",$FORM{'senderemail'});
  62. print "Content-type: text/html\n\n";
  63. &pageheader("Send!");
  64. foreach $line (@temptoken) {
  65.     if ($line =~ m/$token/i) {
  66. <h2>Sent!</h2>
  67. The email has been sent to $FORM{'recipient'}. Please click the back button below to return to the page you were before.<p>
  68. <center><FORM><INPUT type="button" value="Back" onClick="history.go(-2)"></FORM></center>
  69. ~;
  70.     }
  71. print "$line";
  72. }
  73. &powered_by("nologout");
  74. $JUMP_TO = $ENV{'HTTP_REFERER'};
  75. }
  76.  
  77.  
  78. sub send_body {
  79. $req = new HTTP::Request 'GET' => $FORM{'url'};
  80. $res = $ua->request($req);
  81.  
  82. if ($res->is_success) {
  83. #print "Content-type: image/gif\n\n";
  84. #print $res->content;
  85.  
  86.  
  87. open MAIL, "$mailprog" || die "Cannot open $mailprog so I cannot send email";
  88. print MAIL "To: $FORM{'recipientemail'}\n";
  89. print MAIL "From: $FORM{'senderemail'}\n";
  90. print MAIL "Subject: Info Centres Advertisement Stats\n";
  91. print MAIL "Content-type: text/html\n\n";
  92.  
  93. foreach $line ($res->content) {
  94. if ($line =~ /\<body/ig) { $line =~ s/<body(.*?)\>/\<body $1\>$header/ig;}
  95. if ($line =~ /\<head/ig) { $line =~ s/<head>/<head><base href=\"$base\">/ig;}
  96. print MAIL $line;
  97. }
  98. close MAIL;
  99. }
  100. else {
  101. &send_plain;
  102. }
  103. }
  104. sub privacy {
  105. print "Content-type: text/html\n\n";
  106. &pageheader("Privacy Policy");
  107. foreach $line (@temptoken) {
  108.     if ($line =~ m/$token/i) {
  109. print qq~
  110. <h2>Privacy Policy</h2>
  111. ~;
  112. open FILE, $privacy_file || die "Cannot open $privacy_file";
  113. flock(FILE, 2) if $use_flock;
  114. @lines = <FILE>;
  115. flock(FILE, 8) if $use_flock;
  116. close FILE;
  117. print @lines;
  118.     }
  119. print "$line";
  120. }
  121. &powered_by("nologout");
  122. }
  123. sub getbase {
  124. local($baseurl) = @_;
  125. if ($baseurl =~ /\.html?$/i) {
  126. @items = split(/\//,$baseurl);
  127. $n = scalar @items;
  128. $n--;
  129. for($i=0;$i<$n;$i++) {
  130. $base .= @items[$i] . "/";
  131. }
  132. }
  133. else { $base = $baseurl; }
  134. }
  135. sub errors {
  136. local($errors) = @_;
  137. &expires_header("now");
  138. print "Content-type: text/html\n\n";
  139. &pageheader('An error occured');
  140. foreach $line (@temptoken) {
  141.     if ($line =~ m/$token/i) {
  142.         if ($errors eq 'with the email address you gave') {
  143.             print qq~
  144.             <h2>Invalid email address</h2>
  145.             The following email address is invalid: $invalidmail<br>
  146.             Please press the back button and try again.
  147.             ~;
  148.         }
  149. # If the error type was not found:
  150.         else {
  151.         print qq~
  152.         Error Undefined! Please contact <a href="mailto:$webmasteremail?subject=Error_Undefined">$webmasteremail</a> and be detailed in what you did what caused the error.
  153.         ~;
  154.         }
  155. # Back button:
  156. print qq~
  157. <center><FORM><INPUT type="button" value="Back" onClick="history.go(-1)"></FORM></center>
  158. ~;
  159.     }
  160.     print "$line";
  161. }
  162. &powered_by("nologout");
  163. $JUMP_TO = $ENV{'HTTP_REFERER'};
  164. exit; # Exit the script when an error occured.
  165. }

Last edited by Nico; 11-27-07 at 10:49 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-27-07, 01:22 AM
curbview.com's Avatar
curbview.com curbview.com is offline
Junior Code Guru
 
Join Date: May 2006
Posts: 555
Thanks: 0
Thanked 0 Times in 0 Posts
Here you go!

perl Code:
  1. #!/usr/bin/perl
  2.  
  3. $scriptname = "MailPage";
  4. $version = "2.0";
  5.  
  6. use LWP::UserAgent;
  7. $ua = new LWP::UserAgent;
  8. $ua->agent("$ENV{'HTTP_USER_AGENT'}");
  9. use CGI::Carp qw(fatalsToBrowser); # Provides you with fatal error message if they occur.
  10. use CGI qw/:standard/;
  11.  
  12. my $email = 'info@your_site.com'; #THIS WILL BE THE SENDER'S ADDRESS
  13.  
  14. require 'mailpage.conf';
  15. require $mtvwebdesignlib;
  16.  
  17. main: {
  18. &getinput;
  19. &GetCookies;
  20.  
  21. if (lc $FORM{'action'} eq "send") { &getbase($FORM{'url'}); &send; }
  22. elsif (lc $FORM{'action'} eq "privacy") {&privacy;}
  23. else { &moreinfo }
  24.  
  25. }
  26.  
  27.  
  28. sub moreinfo {
  29. $FORM{'url'} = $ENV{'HTTP_REFERER'} unless $FORM{'url'};
  30. if ($FORM{'url'} !~ m/^http/ ) { $FORM{'url'} = $ENV{'HTTP_REFERER'}; }
  31.  
  32. print "Content-type: text/html\n\n";
  33. &pageheader("Email Hits");
  34. foreach $line (@temptoken) {
  35.     if ($line =~ m/$token/i) {
  36. <form action="$ENV{'SCRIPT_NAME'}" method="post">
  37. <input type="hidden" name="action" value="send">
  38. <input type="hidden" name="url" value="$FORM{'url'}">
  39. <TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 >
  40.     <TR>
  41.     <TD>Recipient's Email address<input type="text" name="recipientemail"></TD>
  42.     <td><INPUT TYPE="submit" VALUE="SEND"></td>
  43.     </TR>
  44.   </TABLE>
  45.   </BLOCKQUOTE>
  46. </form>
  47. ~;
  48.     }
  49. print "$line";
  50. }
  51. &powered_by("nologout");
  52. exit;
  53. }
  54. sub send {
  55. &check_email($FORM{'senderemail'});
  56. &send_body;
  57. print "Content-type: text/html\n\n";
  58. &pageheader("Send!");
  59. foreach $line (@temptoken) {
  60.     if ($line =~ m/$token/i) {
  61. print qq~
  62. <h2>Sent!</h2>
  63. The email has been sent to $FORM{'recipient'}. Please click the back button below to return to the page you were before.<p>
  64. <center><FORM><INPUT type="button" value="Back" onClick="history.go(-2)"></FORM></center>
  65. ~;
  66.     }
  67. print "$line";
  68. }
  69. &powered_by("nologout");
  70. $JUMP_TO = $ENV{'HTTP_REFERER'};
  71. exit;
  72. }
  73. sub send_body {
  74. $req = new HTTP::Request 'GET' => $FORM{'url'};
  75. $res = $ua->request($req);
  76. if ($res->is_success) {
  77. #print "Content-type: image/gif\n\n";
  78. #print $res->content;
  79. open MAIL, "$mailprog" || die "Cannot open $mailprog so I cannot send email";
  80. print MAIL "To: $FORM{'recipientemail'}\n";
  81. print MAIL "From: $email\n";
  82. print MAIL "Subject: Info Centres Advertisement Stats\n";
  83. print MAIL "Content-type: text/html\n\n";
  84. foreach $line ($res->content) {
  85. if ($line =~ /\<body/ig) { $line =~ s/<body(.*?)\>/\<body $1\>$header/ig;}
  86. if ($line =~ /\<head/ig) { $line =~ s/<head>/<head><base href=\"$base\">/ig;}
  87. print MAIL $line;
  88. }
  89. close MAIL;
  90. }
  91. else {
  92. &send_plain;
  93. }
  94. }
  95. sub privacy {
  96. print "Content-type: text/html\n\n";
  97. &pageheader("Privacy Policy");
  98. foreach $line (@temptoken) {
  99.     if ($line =~ m/$token/i) {
  100. print qq~
  101. <h2>Privacy Policy</h2>
  102. ~;
  103. open FILE, $privacy_file || die "Cannot open $privacy_file";
  104. flock(FILE, 2) if $use_flock;
  105. @lines = <FILE>;
  106. flock(FILE, 8) if $use_flock;
  107. close FILE;
  108. print @lines;
  109.     }
  110. print "$line";
  111. }
  112. &powered_by("nologout");
  113. }
  114. sub getbase {
  115. local($baseurl) = @_;
  116. if ($baseurl =~ /\.html?$/i) {
  117. @items = split(/\//,$baseurl);
  118. $n = scalar @items;
  119. $n--;
  120. for($i=0;$i<$n;$i++) {
  121. $base .= @items[$i] . "/";
  122. }
  123. }
  124. else { $base = $baseurl; }
  125. }
  126. sub errors {
  127. local($errors) = @_;
  128. &expires_header("now");
  129. print "Content-type: text/html\n\n";
  130. &pageheader('An error occured');
  131. foreach $line (@temptoken) {
  132.     if ($line =~ m/$token/i) {
  133.         if ($errors eq 'with the email address you gave') {
  134.             print qq~
  135.             <h2>Invalid email address</h2>
  136.             The following email address is invalid: $invalidmail<br>
  137.             Please press the back button and try again.
  138.             ~;
  139.         }
  140. # If the error type was not found:
  141.         else {
  142.         print qq~
  143.         Error Undefined! Please contact <a href="mailto:$email?subject=Error_Undefined">$webmasteremail</a> and be detailed in what you did what caused the error.
  144.         ~;
  145.         }
  146. # Back button:
  147. print qq~
  148. <center><FORM><INPUT type="button" value="Back" onClick="history.go(-1)"></FORM></center>
  149. ~;
  150.     }
  151.     print "$line";
  152. }
  153. &powered_by("nologout");
  154. $JUMP_TO = $ENV{'HTTP_REFERER'};
  155. exit; # Exit the script when an error occured.
  156. }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP: Sending a HTML form to an email address cancer10 ASP 1 02-09-07 07:09 PM
Submit Form to entered email address ChuckNorris Perl 4 09-29-06 03:05 PM
formmail problem gscraper Perl 12 08-27-04 04:06 AM


All times are GMT -5. The time now is 09:31 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.