Mood: not sure
I'm confused with the angelfiremail sendmail program. Could anyone email me on what to substitute in different keys($) of the sendmail program. i.e. $class,$self,$message. And this line###..$MAIL->sendMail ($mail_template,\%variables);..### Do I place the name of my mail template file in the key $mail_template and do I put my variables in the %variables hash? Email me at Reekerave@hotmail.com with your help. require AngelfireMail; $MAIL = new AngelfireMail; $mail_template = "./flintstones_mail.txt"; %variables = ('email' => 'Wilma@gurlmail.com', 'name' => 'Wilma', 'number' => '2'); $MAIL->sendMail($mail_template, \%variables); sub new { my $class = shift; my $self = {}; bless $self, $class; return $self; } sub sendMail { # example: $MAIL->sendMail($template_file, \%hash_o_variables) # requires: 1) name of a file that is a template for the mail # 2) a reference to hash of variables to fill out the template # does: writes a mail file to member's directory to be mailed later # by sendmail # returns: 1 on success, 0 on failure my ($self, $template_file, $hash_ref) = @_; my ($message, $key, $time, $file); # error checking if ((! $template_file)||(! $hash_ref)){ print STDERR "usage: sendMail(template_file, hash_reference)\n"; return 0; } if (! -s $template_file){ print STDERR "file does not exist or has a 0 size!\n"; return 0; } # read in template open (MESSAGE, "<$template_file") or die "can't open template file $template for reading\n"; undef $/; $message = ; close (MESSAGE); $/ = "\n"; # variable substitution foreach $key (keys (%{$hash_ref})){ $message =~ s/\$$key/$hash_ref->{$key}/eg; } # check final template format if ($message !~ /to:.*\w+@\w+\.\w+/i){ print STDERR "To: field missing or invalid recipient\n"; return 0; } if ($message !~ /from:.*\w+@\w+\.\w+/i){ print STDERR "From: field missing or invalid sender\n"; return 0; } # write template to file $time = time(); $file = 'mail.'.$time; open (FILE, ">$file") or die "can't open file: $file for writing\n"; print FILE $message; close (FILE); return 1; } 1;
Posted by jazz/e_iray at 4:41 PM EST
|
Post Comment |
View Comments (1) |
Permalink |
Share This Post