I have my following code below to send notifications, newsletters to my registered customers and its working well
my Question is that, is it really efficient and effective to send out mails to over 100k customers emails
CGI CODEMail.pl code#!/usr/bin/perl -wT use strict; use warnings; use CGI qw/:standard/; print "Content-type: text/html\n\n"; print <<HTML; <!doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title>mail sending with progressbar-jquery-ajax-</title> <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightn +ess/jquery-ui.css" rel = "stylesheet"> <script src = "https://code.jquery.com/jquery-1.10.2.js"></scrip +t> <script src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js">< +/script> <style> .ajax-loader { display: inline-block; width: 20px; height: 20px; border: 8px solid #204d74; border-right-color: transparent; border-radius: 50%; animation: spin 1.3s linear infinite; } \@keyframes spin { from { transform: rotate(0deg); opacity: 0.3; } 50% { transform: rotate(180deg); opacity: 1.0; } to { transform: rotate(360deg); opacity: 0.3; } } </style> <script> \$(document).ready(function () { \$("#Submit").click(function(event) { if (\$("form input[name='sub']").val() == "") { \$('#error').text("Subject Required"); return false; } if (\$("form textarea[name='msg']").val() == "") { \$('#error').text("Message Required"); return false; } Execute(); \$('#error').hide(); \$('#progress_start').show(); }); function Execute(){ \$.ajax({ xhr: function() { var xhr = new window.XMLHttpRequest(); //Upload progress xhr.upload.addEventListener("ajax-loader", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; //Do something with upload progress console.log(percentComplete); } }, false); //Download progress xhr.addEventListener("ajax-loader", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; //Do something with download progress console.log(percentComplete); } }, false); return xhr; }, type: 'POST', url: 'mail.pl', data: { 'sub': \$("input[name='sub']").val(), 'msg': \$("textarea[name='msg']").val() }, success: function(res){ \$('#progress_start').hide(); \$('#Response').html(res.msg); }, error: function() { alert("Failed To send Message"); } }); }; }); </script> </head> <body> <br> <form method="post"> <input type="text" id="sub" name="sub" placeholder="Subject"><br><br +> <textarea id="msg" name="msg" placeholder="Message"></textarea><br>< +br> <input type="button" id="Submit" value="Submit"> </form> <div id='progress_start' style='display:none'> <p>Running the task<span class="ajax-loader"></span></p> </div> <div id="Response"></div> <div id="error"></div> </body> </html> HTML
my $sub = $Cgi->param("sub"); my $msg = $Cgi->param("msg"); my $Response; if ($sub) { my $select_emails = $dbh->prepare("SELECT DISTINCT email FROM testuser +"); $select_emails->execute(); my $records = $select_emails->fetchall_arrayref; my @to; for my $em ( @$records ) { push @to, @$em; } for my $recipient(@to) { mail($recipient); } sub mail { my $recipient = shift; my $smtpserver = 'smtp.xxxxxx.com'; my $smtpport = 587; my $smtpuser = 'xxxxx'; my $smtppassword = 'xxxxxx'; 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 => $recipient, From => 'xxxxx@xxxx.com', Subject => $sub, 'Content-Type' => 'text/html', ], body => $msg, ); sendmail($email, { transport => $transport }); $Response = "Done sending"; } my $json = encode_json( { msg => $Response } ); print $Cgi->header( -type => 'application/json' ),$json; } $dbh->disconnect;
In reply to Mail sending by frank1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |