1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #!/usr/bin/perl
local $| = 1;
###### DEBUT DES INFORMATIONS DE CONFIGURATION
# Liste des champs à afficher dans l'email, classés par ordre d'apparition
# !! Respecter les majuscules / minuscules dans le nom des champs !!
@champs=('stage', 'raison', 'adresse', 'codepostal', 'ville', 'nom', 'prenom', 'telephone', 'mail', 'objet');
# Chemin vers sendmail sur votre serveur
$sendmail='/usr/sbin/sendmail';
# Vider l'archive lorsque le nombre d'enregistrements dépasse ce chiffre
$max = 50;
###### FIN DES INFORMATIONS DE CONFIGURATION
###### INUTILE D'EDITER AU DELA DE CETTE LIGNE
use CGI::Carp qw(fatalsToBrowser);
require Text::Iconv ;
print "Content-type:text/html\n\n";
&get_input;
&email;
&archive;
&vide;
sub vide {
$mail = '';
open (FILE3, "archive.txt");
@lines = <FILE3>;
close FILE3;
if ($#lines > $max) {
foreach (@lines) {
chomp;
if ($_ !~ m/[\w\d:]+/) {next;}
$mail .= "$_\r\n";
}
foreach (@mails) {
chomp($_);
open (MAIL,"|$sendmail -t");
print MAIL "To: $_\n";
print MAIL "From: $mails[0]\n";
print MAIL "Content-type:text/html\n";
print MAIL "Subject: Archive des $max derniers enregistrements\n\n";
print MAIL "$mail\r\n";
close MAIL;
}
open (FILE3, ">archive.txt");
print FILE3 "\n";
close FILE3;
}
}
sub archive {
$mail='';
foreach (@champs) {
$mail .= "$param{$_}::";
}
$mail .= "\n";
open (FILE3, ">>archive.txt");
print FILE3 $mail;
close FILE3;
}
sub email {
open(FILE, "emails.txt");
@mails = <FILE>;
close FILE;
open(FILE2, "modele.html");
foreach (<FILE2>) {
$template .= $_;
}
close FILE2;
$template =~ m/<title>(.*?)<\/title>/i;
$sujet = $1;
foreach (@champs) {
$mail .= "<u>$_ :</u> $param{$_}<br>\n";
}
$template =~ s/\*\*\*/$mail/g;
foreach (@mails,$param{'mail'}) {
chomp($_);
open (MAIL,"|$sendmail -t");
print MAIL "To: $_\n";
print MAIL "From: $mails[0]\n";
print MAIL "Content-type:text/html\n";
print MAIL "Subject: $sujet\n\n";
print MAIL "$template\n";
close MAIL;
}
}
sub get_input {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
my $converter = Text::Iconv->new("ISO8859-1", "UTF-8");
my $converter2 = Text::Iconv->new("UTF-8", "Latin-1");
$u = $converter->convert($value);
$value = $converter2->convert($value);
$value =~ s/<!--(.|\n)*-->//g;
chomp($value);
$param{$name} = $value;
$param{$name} =~ s/\r/\n/g;
$param{$name} =~ s/\n/<br>/g;
}
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
my $converter = Text::Iconv->new("ISO8859-1", "UTF-8");
my $converter2 = Text::Iconv->new("ISO8859-1", "Latin-1");
$u = $converter->convert($value);
$value = $converter2->convert($value);
$value =~ s/<!--(.|\n)*-->//g;
chomp($value);
$param{$name} = $value;
$param{$name} =~ s/\r/\n/g;
$param{$name} =~ s/\n/<br>/g;
}
} |
Partager