#!/usr/bin/perl -wT use lib '.'; use warnings; use DBI; use Email::Sender::Simple qw(sendmail); use Email::Sender::Transport::SMTP (); use Email::Simple (); use Email::Simple::Creator (); use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); $CGI::DISABLE_UPLOADS = 1; $CGI::POST_MAX = 1048576; print "Content-type: text/html\n\n"; my $host = "xxxxx"; my $usr = "xxxxx"; my $pwd = "xxxxx"; my $dbname = "xxxxx"; my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; sub getusers { my $sth = $dbh->prepare("SELECT * FROM bmop"); $sth->execute(); while (my @row = $sth->fetchrow_array) { $name = $row[2]; # Get their names $rcpt = $row[5]; # Get their emails push @names,$name; push @rcpts,$rcpt; } } getusers(); sub getready { my $j = 0; foreach my $i(@names){ ## Grab user info from the table $rcv_names = $names[$j]; # Get their name $rcv_emails = $rcpts[$j]; # Get their email mail(); $j++; } } getready(); sub mail { my $sub = "Test mail"; my $msg = "

Hi $rcv_names

"; my $smtpserver = 'xxxx'; my $smtpport = 587; my $smtpuser = 'xxxxx'; my $smtppassword = 'x+x+x+'; my $transport = Email::Sender::Transport::SMTP->new({ host => $smtpserver, ssl => 'starttls', port => $smtpport, sasl_username => $smtpuser, sasl_password => $smtppassword, }); my $email = Email::Simple->create( header => [ To => $rcv_emails, From => 'xxxxx@xxxxx.com', Subject => $sub, 'Content-Type' => 'text/html', ], body => $msg, ); sendmail($email, { transport => $transport }); }