frank1 has asked for the wisdom of the Perl Monks concerning the following question:
Regarding my question on Send email with recipient name, which has taken some time without response, i have came up with something like below, but its not working, even reporting any error.
#!/usr/bin/perl -wT use lib '.'; use strict; 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 = "host"; my $usr = "user"; my $pwd = "pwd"; my $dbname = "datname"; my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; my @names; my @rcpts; my $name; my $rcpt; my $Response; 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; } } sub getready { my $j = 0; foreach my $i(@names){ ## Grab user info from the table $name = $names[$j]; # Get their name $rcpt = $rcpts[$j]; # Get their email sendmail(); $j++; } } sub sendmail { my $sub = "Test mail"; my $msg = "<p> Hi $name </p>"; my $smtpserver = 'smtp.xxxxxx.com'; my $smtpport = 587; my $smtpuser = 'dddddd'; my $smtppassword = 'ddddd'; 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 => $rcpt, From => 'xxx@xxxx.com', Subject => $sub, 'Content-Type' => 'text/html', ], body => $msg, ); sendmail($email, { transport => $transport }); $Response = "Process started"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mail with users names
by hv (Prior) on Jan 01, 2024 at 17:29 UTC | |
by frank1 (Monk) on Jan 01, 2024 at 17:44 UTC | |
by Corion (Patriarch) on Jan 01, 2024 at 19:56 UTC | |
| |
by marto (Cardinal) on Jan 02, 2024 at 10:29 UTC | |
by Bod (Parson) on Jan 01, 2024 at 23:04 UTC | |
|
Re: mail with users names
by tybalt89 (Monsignor) on Jan 02, 2024 at 00:35 UTC | |
by frank1 (Monk) on Jan 02, 2024 at 11:09 UTC | |
|
Re: mail with users names
by Bod (Parson) on Jan 01, 2024 at 22:58 UTC | |
|
Re: mail with users names
by LanX (Saint) on Jan 01, 2024 at 16:51 UTC | |
|
Re: mail with users names
by choroba (Cardinal) on Jan 04, 2024 at 14:40 UTC | |
by marto (Cardinal) on Jan 04, 2024 at 16:44 UTC | |
by frank1 (Monk) on Jan 06, 2024 at 18:19 UTC |