View Single Post
  #2 (permalink)  
Old 11-27-07, 12: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. }
Reply With Quote