almost the same script...different results
almost the same script...different results
(OP)
I have 2 scripts on the same server that are performing differently. One of them sends an e-mail with the correct "from" line and the correct subject. The other sends an e-mail to the correct recipient, but the from line is just the default address of the server(I'm guessing that's what it is).
here are the 2 scripts:
first the smaller one that works:
#!/usr/local/bin/perl
###################
# Program Variables
$mail_prog = "/usr/bin/sendmail";
#$mail_prog = "/var/qmail/bin/qmail-inject";
###################
# Program Execution
&send_mail;
&ret_html;
exit;
#################
# Sends an e-mail
sub send_mail {
open(MAIL,"|$mail_prog -t");
print MAIL "To: dpfrey\@home.com\n";
print MAIL "From: Limestone <limestone\@limestonemusic.com>\n";
print MAIL "Subject: HI there\n";
print MAIL "Mime-Version: 1.0\n";
print MAIL "X-Mailer: Limestone Mailer v1.0\n";
print MAIL "Content-Type: text/plain\n\n";
print MAIL "This is the body\n";
print MAIL ".";
close(MAIL);
}
##########################
# Returns an HTML document
sub ret_html {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Mailing List Sender</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Mail has been sent\n";
print "</body>\n";
print "</html>\n";
}
now the one that doesn't work properly:
#!/usr/local/bin/perl
###################
# Program Variables
$from = "Limestone Mailing List";
$list_file = "list.txt";
#$basedir = "/data1/hypermart.net/limestone";
$basedir = "/home/livevic/public_html/limestone";
$mail_prog = "/usr/bin/sendmail";
#$mail_prog = "/var/qmail/bin/qmail-inject";
$login = "limestone";
$password = "palpro";
# Use the CGI object
use CGI;
$cgiobject = new CGI;
$form_login = $cgiobject->param("login");
$form_password = $cgiobject->param("password");
$subject = $cgiobject->param("subject");
$body = $cgiobject->param("body");
###################
# Program Execution
&check_lp;
if($access == 1) {
&get_address;
&ret_html;
}
else {
&ret_error;
}
exit;
#########################
# Verifies the login/pass
sub check_lp {
if($form_login eq $login && $form_password eq $password) {
$access = 1;
}
else {
$access = 0;
}
}
####################################
# Retrieves addresses from list file
sub get_address {
open(LIST,"$basedir/$list_file");
@lines = <LIST>;
close(LIST);
open(LIST,"$basedir/$list_file");
foreach $line (@lines) {
unless ($line =~ /<!-- END -->/) {
&send_email($line);
}
}
close(LIST);
}
#################
# Sends an e-mail
sub send_email {
$recipient = $_[0];
open(MAIL,"|$mail_prog -t");
print MAIL "To: $recipient\n";
print MAIL "From: Limestone \<limestone\@limestonemusic.com\>\n";
print MAIL "Subject: $subject\n";
print MAIL "Mime-Version: 1.0\n";
print MAIL "X-Mailer: Limestone Mailer v1.0\n";
print MAIL "Content-Type: text/plain\n\n";
print MAIL "$body\n";
print MAIL "To unsubscribe, go to: http://www.limestone.livevictoria.com/maillist.pl\?remove=$recipient\n";
print MAIL ".";
close(MAIL);
}
##########################
# Returns an HTML document
sub ret_html {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Mailing List Sender</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Message has been sent.\n";
print "</body>\n";
print "</html>\n";
}
###############################
# Prints a login/password error
sub ret_error {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Error</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Incorrect login/password $form_login/$form_password\n";
print "</body>\n";
print "</html>\n";
}
Thanks for your help
here are the 2 scripts:
first the smaller one that works:
#!/usr/local/bin/perl
###################
# Program Variables
$mail_prog = "/usr/bin/sendmail";
#$mail_prog = "/var/qmail/bin/qmail-inject";
###################
# Program Execution
&send_mail;
&ret_html;
exit;
#################
# Sends an e-mail
sub send_mail {
open(MAIL,"|$mail_prog -t");
print MAIL "To: dpfrey\@home.com\n";
print MAIL "From: Limestone <limestone\@limestonemusic.com>\n";
print MAIL "Subject: HI there\n";
print MAIL "Mime-Version: 1.0\n";
print MAIL "X-Mailer: Limestone Mailer v1.0\n";
print MAIL "Content-Type: text/plain\n\n";
print MAIL "This is the body\n";
print MAIL ".";
close(MAIL);
}
##########################
# Returns an HTML document
sub ret_html {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Mailing List Sender</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Mail has been sent\n";
print "</body>\n";
print "</html>\n";
}
now the one that doesn't work properly:
#!/usr/local/bin/perl
###################
# Program Variables
$from = "Limestone Mailing List";
$list_file = "list.txt";
#$basedir = "/data1/hypermart.net/limestone";
$basedir = "/home/livevic/public_html/limestone";
$mail_prog = "/usr/bin/sendmail";
#$mail_prog = "/var/qmail/bin/qmail-inject";
$login = "limestone";
$password = "palpro";
# Use the CGI object
use CGI;
$cgiobject = new CGI;
$form_login = $cgiobject->param("login");
$form_password = $cgiobject->param("password");
$subject = $cgiobject->param("subject");
$body = $cgiobject->param("body");
###################
# Program Execution
&check_lp;
if($access == 1) {
&get_address;
&ret_html;
}
else {
&ret_error;
}
exit;
#########################
# Verifies the login/pass
sub check_lp {
if($form_login eq $login && $form_password eq $password) {
$access = 1;
}
else {
$access = 0;
}
}
####################################
# Retrieves addresses from list file
sub get_address {
open(LIST,"$basedir/$list_file");
@lines = <LIST>;
close(LIST);
open(LIST,"$basedir/$list_file");
foreach $line (@lines) {
unless ($line =~ /<!-- END -->/) {
&send_email($line);
}
}
close(LIST);
}
#################
# Sends an e-mail
sub send_email {
$recipient = $_[0];
open(MAIL,"|$mail_prog -t");
print MAIL "To: $recipient\n";
print MAIL "From: Limestone \<limestone\@limestonemusic.com\>\n";
print MAIL "Subject: $subject\n";
print MAIL "Mime-Version: 1.0\n";
print MAIL "X-Mailer: Limestone Mailer v1.0\n";
print MAIL "Content-Type: text/plain\n\n";
print MAIL "$body\n";
print MAIL "To unsubscribe, go to: http://www.limestone.livevictoria.com/maillist.pl\?remove=$recipient\n";
print MAIL ".";
close(MAIL);
}
##########################
# Returns an HTML document
sub ret_html {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Mailing List Sender</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Message has been sent.\n";
print "</body>\n";
print "</html>\n";
}
###############################
# Prints a login/password error
sub ret_error {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print " <title>Limestone: Error</title>\n";
print " <link href=\"stylesheet.css\" type=\"text/css\" rel=\"stylesheet\">\n";
print "</head>\n";
print "<body bgcolor=\"#000000\">\n";
print "Incorrect login/password $form_login/$form_password\n";
print "</body>\n";
print "</html>\n";
}
Thanks for your help
RE: almost the same script...different results
Sincerely,
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com
RE: almost the same script...different results
unfortuneately it didn't work. What was that supposed to do? It still did exactly the same thing it did before.
I'm really stumped here.
RE: almost the same script...different results
Make sure there aren't any newlines in $recipient or you may newline it twice and send the remaining header into the body.
BTW, you shouldn't send each address in your list a seperate email... you should BCC it. Go to FAQ219-364 to see how.
Sincerely,
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com
RE: almost the same script...different results
The reason it worked is the list I was pulling the e-mail addresses has one addy per line therefore there is a newline at the end of each already.
Thanks again