Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

almost the same script...different results

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
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 &quot;From: Limestone <limestone\@limestonemusic.com>\n&quot;;
print MAIL &quot;Subject: HI there\n&quot;;
print MAIL &quot;Mime-Version: 1.0\n&quot;;
print MAIL &quot;X-Mailer: Limestone Mailer v1.0\n&quot;;
print MAIL &quot;Content-Type: text/plain\n\n&quot;;
print MAIL &quot;This is the body\n&quot;;
print MAIL &quot;.&quot;;
close(MAIL);
}

##########################
# Returns an HTML document
sub ret_html {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot; <title>Limestone: Mailing List Sender</title>\n&quot;;
print &quot; <link href=\&quot;stylesheet.css\&quot; type=\&quot;text/css\&quot; rel=\&quot;stylesheet\&quot;>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body bgcolor=\&quot;#000000\&quot;>\n&quot;;
print &quot;Mail has been sent\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>\n&quot;;
}




now the one that doesn't work properly:

#!/usr/local/bin/perl

###################
# Program Variables
$from = &quot;Limestone Mailing List&quot;;
$list_file = &quot;list.txt&quot;;
#$basedir = &quot;/data1/hypermart.net/limestone&quot;;
$basedir = &quot;/home/livevic/public_html/limestone&quot;;
$mail_prog = &quot;/usr/bin/sendmail&quot;;
#$mail_prog = &quot;/var/qmail/bin/qmail-inject&quot;;
$login = &quot;limestone&quot;;
$password = &quot;palpro&quot;;

# Use the CGI object
use CGI;
$cgiobject = new CGI;

$form_login = $cgiobject->param(&quot;login&quot;);
$form_password = $cgiobject->param(&quot;password&quot;);
$subject = $cgiobject->param(&quot;subject&quot;);
$body = $cgiobject->param(&quot;body&quot;);

###################
# Program Execution
&amp;check_lp;
if($access == 1) {
&amp;get_address;
&amp;ret_html;
}
else {
&amp;ret_error;
}
exit;

#########################
# Verifies the login/pass
sub check_lp {
if($form_login eq $login &amp;&amp; $form_password eq $password) {
$access = 1;
}
else {
$access = 0;
}
}

####################################
# Retrieves addresses from list file
sub get_address {
open(LIST,&quot;$basedir/$list_file&quot;);
@lines = <LIST>;
close(LIST);

open(LIST,&quot;$basedir/$list_file&quot;);
foreach $line (@lines) {
unless ($line =~ /<!-- END -->/) {
&amp;send_email($line);
}
}
close(LIST);
}

#################
# Sends an e-mail
sub send_email {
$recipient = $_[0];
open(MAIL,&quot;|$mail_prog -t&quot;);
print MAIL &quot;To: $recipient\n&quot;;
print MAIL &quot;From: Limestone \<limestone\@limestonemusic.com\>\n&quot;;
print MAIL &quot;Subject: $subject\n&quot;;
print MAIL &quot;Mime-Version: 1.0\n&quot;;
print MAIL &quot;X-Mailer: Limestone Mailer v1.0\n&quot;;
print MAIL &quot;Content-Type: text/plain\n\n&quot;;
print MAIL &quot;$body\n&quot;;
print MAIL &quot;To unsubscribe, go to: print MAIL &quot;.&quot;;
close(MAIL);
}

##########################
# Returns an HTML document
sub ret_html {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot; <title>Limestone: Mailing List Sender</title>\n&quot;;
print &quot; <link href=\&quot;stylesheet.css\&quot; type=\&quot;text/css\&quot; rel=\&quot;stylesheet\&quot;>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body bgcolor=\&quot;#000000\&quot;>\n&quot;;
print &quot;Message has been sent.\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>\n&quot;;
}

###############################
# Prints a login/password error
sub ret_error {
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<html>\n&quot;;
print &quot;<head>\n&quot;;
print &quot; <title>Limestone: Error</title>\n&quot;;
print &quot; <link href=\&quot;stylesheet.css\&quot; type=\&quot;text/css\&quot; rel=\&quot;stylesheet\&quot;>\n&quot;;
print &quot;</head>\n&quot;;
print &quot;<body bgcolor=\&quot;#000000\&quot;>\n&quot;;
print &quot;Incorrect login/password $form_login/$form_password\n&quot;;
print &quot;</body>\n&quot;;
print &quot;</html>\n&quot;;
}


Thanks for your help
 
Thanks for the tip.
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.
 
You should put the name in quotes followed by the address in angled brackets. That is the standard method and it should work. You don't need to escape the brackets. If you use qq~~ then you don't have to escape quotes.

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.
 
I took the \n out after $recipient in the mail section and it worked....
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top