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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

This has me stumped :( Regarding sendmail

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
1) The script keeps on sending out blank emails that have not sender, recepient, date, or anything!

2) The script keeps on seeing to 'miss' emails being sent. E.g if I am meant to send out 12, it will send out 10. There does not seem to be a patter to the ones it misses out :(

The code is;
Code:
#!/usr/bin/perl

print "Content-type: text/html \n\n";

$sendmail = "/usr/sbin/sendmail";



use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);

# Get the info we need.
# $query = new CGI;
# $sendthanks = $query->param('sendthanks');



open(MONTH,"months.ace") || die &error;
$month = <MONTH>;
close(MONTH);

open(MONTH,&quot;>months.ace&quot;) || die &error;
$new_month = $month + 1;
print MONTH &quot;$new_month&quot;;
close(MONTH);

# Get the data
open(DATES,&quot;dates.ace&quot;) || die &error;
flock(DATES, 2);
@dates = <DATES>;
close(DATES);


@send = qw();

foreach $person (@dates)
{
($username, $emailaddress, $exp_date) = split(/::/, $person);

if ($exp_date == $month) 

       { push(@send, &quot;$username\:\:$emailaddress&quot;);

    }
} # End the foreach loop.

&add;
&admin_send;

sub add
{
foreach $line (@send)
{
my ($username, $email) = split(/::/, $line);
flock(MAIL, 2);
open(MAIL,&quot;|$sendmail -t&quot;); # || die &error;
print MAIL &quot;To: $email  \n&quot;;
print MAIL &quot;From: support\@vgacd.com \n&quot;;
print MAIL &quot;Reply-to: support\@vgacd.com \n&quot;;
print MAIL &quot;Subject: RE\: Your membership for username \&quot;$username\&quot;..... \n\n&quot;;
close(MAIL);
print &quot;sent $username <BR>\n&quot;;
} # End the foreach loop

}

sub admin_send
{
print &quot;Sent email to admin&quot;;
}

sub error
{
print &quot;<BR><BR>There was an error opening the file&quot;;
}


and the content of months.ace is like 32

The content of dates.ace is;

Code:
4andy::webmaster@ace-installer.com::29
4andy::webmaster@ace-installer.com::29
4andy::webmaster@ace-installer.com::29
4andy::webmaster@ace-installer.com::30
4andy::webmaster@ace-installer.com::30
4andy::webmaster@ace-installer.com::30
4andy::webmaster@ace-installer.com::31
4andy::webmaster@ace-installer.com::31
4andy::webmaster@ace-installer.com::31
4andy::webmaster@ace-installer.com::32
4andy::webmaster@ace-installer.com::32
4andy::webmaster@ace-installer.com::32
4andy::webmaster@ace-installer.com::33
4andy::webmaster@ace-installer.com::33
4andy::webmaster@ace-installer.com::33
4andy::webmaster@ace-installer.com::34
4andy::webmaster@ace-installer.com::34
4andy::webmaster@ace-installer.com::34
1andy::webmaster@ace-installer.com::35
2andy::webmaster@ace-installer.com::35
3andy::webmaster@ace-installer.com::35
1andy::webmaster@ace-installer.com::35
2andy::webmaster@ace-installer.com::35
3andy::webmaster@ace-installer.com::35
1andy::webmaster@ace-installer.com::35
2andy::webmaster@ace-installer.com::35
3andy::webmaster@ace-installer.com::35
1andy::webmaster@ace-installer.com::35
2andy::webmaster@ace-installer.com::35
3andy::webmaster@ace-installer.com::35
4andy::webmaster@ace-installer.com::36
4andy::webmaster@ace-installer.com::36
4andy::webmaster@ace-installer.com::36
4andy::webmaster@ace-installer.com::36


I have been working on this all day, and I am still n closer to solving it :(

Could some one pleeeeeeeeeeese help me!

Thanks

Andy
 
Nobody??? PRETTY PLEASE ;)

I really need to try and see what is going on.

Andy
 
I can only see one potential problem. You're not removing the newline off the end of your data records from dates.ace. Therefore when you split it, the last field will contain a newline at the end. Try adding this line right after you read dates.ace into @dates.
Code:
map(chomp,@dates);
Also, I don't think it's necessary to flock MAIL.

If those things don't help, let me know and I'll take another look.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Tracey's right - you don't need to flock the sendmail process. And actually, you're locking it before it exists...

I've pretty much stopped using sendmail to send mail - I use the Net::SMTP module now, much easier. Have a look on CPAN. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
I'll have to take a look at that module myself. I still use sendmail, but a long time ago I wrote myself a subroutine to use it that simplifies the process considerably. That's probably why I haven't switched.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I've decided to keep to Sendmail at the moment, as I'm not sure my server has the SMTP module.

As for the code. I am now using the below code;

Code:
#!/usr/bin/perl

print &quot;Content-type: text/html \n\n&quot;;

$sendmail = &quot;/usr/sbin/sendmail&quot;;

use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);


open(MONTH,&quot;months.ace&quot;) || die &error;
$month = <MONTH>;
close(MONTH);

open(MONTH,&quot;>months.ace&quot;) || die &error;
$new_month = $month + 1;
print MONTH &quot;$new_month&quot;;
close(MONTH);

# Get the data
open(DATES,&quot;dates.ace&quot;) || die &error;
flock(DATES, 2);
@dates = <DATES>;
map(chomp,@dates);
close(DATES);



foreach $person (@dates)
{
($username, $emailaddress, $exp_date) = split(/::/, $person);

if ($exp_date == $month) 

       { 
open(MAIL,&quot;|$sendmail -t&quot;) || die &error;
print MAIL &quot;To: $emailaddress  \n&quot;;
print MAIL &quot;From: support\@vgacd.com \n&quot;;
print MAIL &quot;Reply-to: support\@vgacd.com \n&quot;;
print MAIL &quot;Subject: RE\: Your membership for username \&quot;$username\&quot;.....  \n\n&quot;;
close(MAIL);

print &quot;sent $username sent to $emailaddress<BR>\n&quot;;
    }
} # End the foreach loop.


sub admin_send
{
print &quot;Sent email to admin&quot;;
}

sub error
{
print &quot;<BR><BR>There was an error opening the file&quot;;
}

Still, for some reason blank emails are being sent, and emails are being missed out :(

Does anyone have some more comments and ideas as to why this may be happening?

Thanks

Andy
 
I just ran the code almost exactly like you have it directly above (I changed the path to the data files and added a couple of extra prints for debugging) and it's working fine. I don't always get the emails in order, but I get them. Of course, the text of the email is blank, because you don't print anything into the text, but the email comes thru fine. I also changed the data file to look like this, so I could see what was being sent for each data line, and to send them to me:
Code:
29-1userid::tracy@bydisn.com::29
29-2userid::tracy@bydisn.com::29
If you don't want the email to be empty, add a print after the subject line (leave it with \n\n on it) to print the email text.

Unless your email is somehow losing mail, I can't see a problem.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Ok. Thanks everyone. I will try it on one of my other sites, and see how it goes :s

Andy
 
Ok. I got it kinda sorted. What I did was change it to my hotmail email address, and it worked fine! I got every email! I don't know what the heck happened, but for some reason it was missing emails when sending it from sendmail to POP 3 addresses :(

Maybe the POP3 server was getting overload?

Anyway, thanks for you help :)

Andy
 
It also may have something to do with the fact that you were sending what were essentially duplicate emails. Same to address, same from address, same subject, etc.
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top