View Single Post
  #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.
Reply With Quote