#!/usr/bin/perl # # MASTER COPY # #--------------------------------------------------- # C R O O K E D B U S H . C O M - R U N A u t o F O L L O W U P. # Designed by Jason Silver of Intelliscript.net, CrookedBush.com Inc. # All Rights Reserved. International Copyright Secured. # Violators Will Be Prosecuted to the FULL EXTENT of the law. # Do Not remove this copyright notice. #--------------------------------------------------- $file_lock = 1; $copyright = '(c)2002 Intelliscript.net. All Rights Reserved. International Copyright Secured.'; $version = '30303-0105'; #___________________________ #--------------------------- #print "Content-type: text/html\n\n"; &open_global_variables; &open_data_file; &send_out_autoreponders; &print_gif; exit; #--------------------------- #--------------------------- # Send Out AutoResponders #--------------------------- sub send_out_autoreponders{ LOOP: foreach $product_key (sort (keys %PRODUCTS)){ ($senders_name, $senders_email, $number_of_letters, $mailout_interval, $unsubscribe, $send_reports, $redirect_page, $newsletter, $purge_list, $rotate_list, $reply_name, $reply_email) = split(/\|/, $PRODUCTS{$product_key}); @mailout_interval = split (/,/, $mailout_interval); foreach $interval (@mailout_interval){ ($letter, $days) = split (/-/, $interval); $INTERVAL{$letter} = $days; }#foreach if ($file_lock) { flock(PROSPECTS_FILE,2) } open(PROSPECTS_FILE,"$followup_letters$product_key.txt"); @prospects = ; foreach $line_number (0..$#prospects){ ($clients_email, $date_last_sent, $letter_to_send, $clients_name, $field_1, $field_2, $field_3, $field_4, $field_5, $clients_ip_address) = split(/&/, $prospects[$line_number]); if($letter_to_send<1){$letter_to_send = 0} if($letter_to_send > $number_of_letters) { next } &calculate_elapsed_days; # since last sending if($elapsed_days >= $INTERVAL{$letter_to_send} && $count < $email_limit){ chomp ($letter_to_send); $letter_filename = $product_key."_reminder_".$letter_to_send.".txt"; if(&open_letter($letter_filename)){ $count++;# add count so we don't pass the email limit # send mail to this recipient chomp ($clients_name); $mail_from = $senders_name." <".$senders_email.">"; $reply_to = $reply_name." <".$reply_email.">"; $mail_to = $clients_name." <".$clients_email.">"; $subject = $letter_data[0]; if ($subject =~ /\%\%html\%\%/){ $html_message = "checked"; $subject =~ s/\%\%html\%\%//; } ($clients_first_name, $clients_last_name) = split (/ /, $clients_name); chomp ($clients_first_name); chomp ($clients_last_name); chomp ($clients_name); $subject =~ s/\[FULLNAME\]/$clients_name/sgi; $subject =~ s/\[EMAIL\]/$clients_email/sgi; $subject =~ s/\[FIRSTNAME\]/$clients_first_name/sgi; $subject =~ s/\[LASTNAME\]/$clients_last_name/sgi; splice @letter_data, 0, 1; $message = join("", @letter_data); $message =~ s/\[FULLNAME\]/$clients_name/sgi; $message =~ s/\[EMAIL\]/$clients_email/sgi; $message =~ s/\[FIRSTNAME\]/$clients_first_name/sgi; $message =~ s/\[LASTNAME\]/$clients_last_name/sgi; $message =~ s/\[IP\]/$clients_ip_address/sgi; if ($message =~ /\[FIELD/){ foreach $field_number(1..5){ $sub_field = "field_".$field_number; $message =~ s/\[FIELD$field_number\]/$$sub_field/sgi; } } if ($message =~ /\[INCREMENT\]/){ if($file_lock){ flock(INCREMENT,2) } open (INCREMENT,"$followup_letters$product_key"."_incr.txt"); $increment = + 1; open (INCREMENT, ">$followup_letters$product_key"."_incr.txt"); print INCREMENT $increment; close (INCREMENT); if ($file_lock) { flock(INCREMENT,8) } $message =~ s/\[INCREMENT\]/$increment/sgi; } if ($unsubscribe){ $remove_link = $product_key; $remove_link =~ s/temp_//i; $message .= "\n\nTo remove your email address from the list, go here:\n$url_of_followup?remove=$clients_email&product=$remove_link" } &mail_it; # add email to array for reporting results to admin and saving results to server $remove_link = $product_key; $remove_link =~ s/temp_//i; $LETTERS_SENT{$clients_email} = qq~ $clients_name$letter_to_send$elapsed_days$date_last_sentremove ~; $letter_to_send++; if ($letter_to_send >= $number_of_letters && $rotate_list){ $letter_to_send = 0 }#if $prospects[$line_number] = $clients_email."\&".localtime(time)."\&".$letter_to_send."\&".$clients_name."\&".$field_1."\&".$field_2."\&".$field_3."\&".$field_4."\&".$field_5."\&".$clients_ip_address; if ($letter_to_send >= $number_of_letters && $purge_list){ splice @prospects, $line_number, 1; }#if }#if else { print "
CAN'T OPEN LETTER
" if ($troubleshoot)} }#end of if elsif($count > $email_limit){ last LOOP } }# end of foreach $file_name = $product_key.".txt"; &save_prospects_data($file_name); # send summary e-mail to administrator if($send_reports && scalar(keys %LETTERS_SENT)){ $mail_from = $senders_name." <".$senders_email.">"; $mail_to = $senders_name." <".$senders_email.">"; $subject = "Mailing Summary for ".$product_key; foreach $key (keys %LETTERS_SENT){ $info = $info.$LETTERS_SENT{$key}; delete $LETTERS_SENT{$key}; # emails from last report }# end of foreach $message = qq~Content-Type: text/html Hello there, $senders_name,

I've just sent Auto FollowUp e-mails automatically.
There are $number_of_letters letters, and the mailing interval is
$mailout_interval.

The email limit is set to $email_limit simultaneous mailouts.
Product: $product_key
Unsubscribe: $unsubscribe
Send Reports: $send_reports
Add to newsletter: $newsletter
Purge records: $purge_list
Rotate List: $rotate_list
Redirect Page: $redirect_page
$info
NameLetter to SendElapsed DaysDate Last SentRemove
Yours,
Intelliscript.net Auto Followup Script --ffff Content-Type: text/plain Hello there, $senders_name, I've just sent Auto FollowUp e-mails automatically. There are $number_of_letters letters, and the mailing interval is $mailout_interval The email limit is set to $email_limit simultaneous mailouts. Product: $product_key Unsubscribe: $unsubscribe Send Reports: $send_reports Add to newsletter: $newsletter Purge records: $purge_list Rotate List: $rotate_list Redirect Page: $redirect_page This info won't display properly with your plain text email program: $info Yours, Intelliscript.net Auto Followup Script ~; $html_message = "checked"; &mail_it; }#if }#foreach }#sub send_out_autoreponders #--------------------------- # Calcualte Elapsed Days #--------------------------- sub calculate_elapsed_days{ # Now go through string date from server(eg: Wed Nov 1 16:46:22 2000) # and translate it to Perl MARTIAN TIME! $date_last_sent =~ s/ / /sgi; @date_break_down = split(/ /, $date_last_sent); $month_name_then = $date_break_down[1]; $month_day_then = $date_break_down[2]; $year_then = $date_break_down[4]; if ($month_name_then eq "Jan"){ $days_in_year_then = 0 } if ($month_name_then eq "Feb"){ $days_in_year_then = 31 } if ($month_name_then eq "Mar"){ $days_in_year_then = 59 } if ($month_name_then eq "Apr"){ $days_in_year_then = 90 } if ($month_name_then eq "May"){ $days_in_year_then = 120 } if ($month_name_then eq "Jun"){ $days_in_year_then = 151 } if ($month_name_then eq "Jul"){ $days_in_year_then = 181 } if ($month_name_then eq "Aug"){ $days_in_year_then = 212 } if ($month_name_then eq "Sep"){ $days_in_year_then = 243 } if ($month_name_then eq "Oct"){ $days_in_year_then = 273 } if ($month_name_then eq "Nov"){ $days_in_year_then = 304 } if ($month_name_then eq "Dec"){ $days_in_year_then = 334 } $days_in_year_then = $days_in_year_then + $month_day_then; # add the day of the month to the total days passed ($sec_now,$min_now,$hour_now,$month_day_now,$month_now,$year_now,$week_day_now,$days_in_year_now,$isdst_now) = localtime(time); $year_now = $year_now + 1900; $elapsed_days = $days_in_year_now - $days_in_year_then + 1; if ($year_then < $year_now) { $elapsed_days = 365 + $elapsed_days + $days_in_year_now; } }#sub calculate_elapsed_days #--------------------------- # Open Letter on Server #--------------------------- sub open_letter{ my ($letter_file) = @_; open (LETTER, "$followup_letters$letter_file") || return 0; @letter_data = ; close (LETTER); } # end of sub open_letter #--------------------------- # Open Global Variables #--------------------------- sub open_global_variables{ open(VARIABLES,"variables.cgi"); @variables=; close (VARIABLES); chomp (@variables); $followup_letters = $variables[0]; $data_file = $variables[1]; $user_file = $variables[2]; $admin_name = $variables[3]; $admin_email = $variables[4]; $auto_mailing_interval = $variables[5]; $confirm_page = $variables[6]; $url_of_followup = $variables[7]; $body_tag = $variables[8]; $header_image_html= $variables[9]; $email_program = $variables[10]; $email_limit = $variables[11]; $mailing_list = $variables[12]; $list_name = $variables[13]; }#sub open_global_variables #--------------------------- # Open DATA file #--------------------------- sub open_data_file{ open(DATA_FILE,"$data_file") || &create_data_file; @DATA = ; close(DATA_FILE); chomp (@DATA); foreach $line (@DATA){ ($product, $senders_name, $senders_email, $number_of_letters, $mailout_interval, $unsubscribe, $send_reports, $redirect_page, $newsletter, $purge_list, $rotate_list, $reply_name, $reply_email) = split(/\|/, $line); $PRODUCTS{$product} = $senders_name."\|".$senders_email."\|".$number_of_letters."\|".$mailout_interval."\|".$unsubscribe."\|".$send_reports."\|".$redirect_page."\|".$newsletter."\|".$purge_list."\|".$rotate_list."\|".$reply_name."\|".$reply_email; }# end of foreach $line }#sub open_data_file #--------------------------- # Mail It Out #--------------------------- sub mail_it{ if ($html_message){ chomp ($subject); $message = "MIME-Version: 1.0\nContent-Type: multipart/alternative;\n boundary=\"ffff\"\nThis is a multipart message in MIME format.\n\n--ffff\n".$message."\n\n\n\n\nAuto FollowUp Version $version by Intelliscript.net\n\n--ffff--"; $html_message = (); } print "Mailing
\n" if ($troubleshoot); open(MAIL,"|$email_program -t") or print_browser_and_exit("Error!","Can't open mail program Error: $!"); print MAIL "To: $mail_to\n"; print MAIL "Reply-To: $reply_to\n" if ($reply_to); print MAIL "From: $mail_from\n"; print MAIL "Subject: $subject\n"; print MAIL "$message"; close (MAIL); # $def_smtp_server = 'mailserver.com'; # &send_mail; } # end of sub mail_it #--------------------------- # Save Prospects to File #--------------------------- sub save_prospects_data{ my ($file_to_save) = @_; print "File to save: ".$file_to_save."
" if ($troubleshoot); # Check for missing email addresses and delete those lines chomp (@prospects); @prospects = grep(/\@/i,@prospects); $write_data = join("\n",@prospects); open (PROSPECTS_FILE, ">$followup_letters$file_to_save") or &print_browser_and_exit("Write Error","I can't open the prospects file: $followup_letters$file_to_save.
Error Code: $!"); print PROSPECTS_FILE "$write_data"; close (PROSPECTS_FILE); if ($file_lock) { flock(PROSPECTS_FILE,8) } } # sub save_prospects_data #--------------------------- # Print 1 Pixel by 1 Pixel Gif and Exit #--------------------------- sub print_gif{ my $gif = pack "H*",'47494638396101000100800000ffffff00000021f90401000000002c00000000010001000002024401003b'; binmode STDOUT; # for Win32 users print "Content-type: image/gif\r\n"; print "Content-length: 43\r\n\r\n"; print $gif; exit; }#sub print_gif #--------------------------- # Print to Browser and Exit #--------------------------- sub print_browser_and_exit{ my($title,$message) = @_; print "Content-type: text/html\n\n"; print < $title $body_tag

$title

$message
HTML exit; }#print_browser_and_exit