I'm having problem with my send mail script. Mostly the problem is all about the progress bar. I want when I click submit that the progress bar starts moving and ends when the sending done.
Well, I have tried to take similar examples CGI::ProgressBar but I can't make it work.
#!/usr/bin/perl -w
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
use CGI;
use MIME::Lite;
use CGI::ProgressBar qw/:standard/;
$| = 1; # Do not buffer output
my $CGI = CGI->new();
my $from_email = $CGI->param("from_email");
my $from_name = $CGI->param("from_name");
my $subject = $CGI->param("subject");
my $receipts = $CGI->param("receipts");
my $message = $CGI->param("message");
# Newline format. send message to each email listed
my $output = join "
", split " ", $receipts;
if ($from_email, $from_name, $subject, $receipts, $message) {
my $msg = MIME::Lite->new(
# From Name: John Deo And Sent From Email: [email protected]
From => "$from_name <$from_email>",
To => $output,
Subject => $subject,
Data => $message
);
# Support HTML Message
$msg->attr("content-type" => "text/html");
$msg->send;
if ($msg) { # if mail starts sending
print progress_bar( -from=>1, -to=>100 );
for (1..100){
print update_progress_bar;
# Print ProgressBar
$progressbar_html = qq{<div class="box">
<div id="progressbar">
<div></div>
</div>
<div class="text">Sending... 1%</div>
</div>
};
sleep 1;
}
print $response = "Message Sent Successfully";
exit;
}
if(!$msg) {
print $response = "Message Failed To Send";
}
}
print "Content-type: text/html
";
print <<START_HTML;
<!DOCTYPE html>
<html>
<head>
<title>Simple Mailer</title>
<style type="text/css">
.box {
border-radius: 10px;
padding: 25px;
background-color: rgba(51, 51, 51, 0.96);
text-align: center;
}
#progressbar {
border: 3px solid #fff;
border-radius: 20px;
padding: 2px;
}
#progressbar > div {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
background-color: #fff;
width: 1%;
height: 18px;
border: 1px solid rgba(0, 0, 0, 0);
border-radius: 20px;
}
.text {
color: #fff;
margin-top: 15px;
font-size: 21px;
font-weight: bold;
}
</style>
</head>
<body>
<form method="post">
<label>From Email
<input type="text" name="from_email" />
<br />
<br />
From Name
<input type="text" name="from_name" />
</label>
<p>
<label>Subject
<input type="text" name="subject" />
</label>
</p>
<p>
<label>Receipts
<textarea name="receipts"></textarea>
</label>
</p>
<p>
<label>message
<textarea name="message"></textarea>
</label>
</p>
<p>
<label>Send
<input type="submit" value="Submit" />
</label>
</p>
</form>
<p> </p>
$progressbar_html
<p>$response</p>
</body>
</html>
START_HTML
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…