×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

almost the same script...different results

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

RE: almost the same script...different results

(OP)
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.

RE: almost the same script...different results

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.
http://www.oac-design.com

RE: almost the same script...different results

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close