|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Once again I've come back for help.
I've got a page where an "author" can come, select which list he wants to post too; then clicks submit, having it emailed to everyone in the db that is subcrided to that list. ------------------------------------------ Problem: it's not working. ------------------------------------------ mysql db in breif: id int(11) pri auto_increment email varchar(64) news1 char(3) news2 char(3) -------------------------------------- output: id email news1 news2 0 test@test.com yes NULL ------------------------------------------ test@test.com is subscribed to news1, and not news2. --------------------------------------------- mailsender, perl script: #!/usr/local/bin/perl -w use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser/; use DBI; use Mail::Sender; $drh = DBI->install_driver( 'mysql' ); $dbh=$drh->connect("DBName","User","Pass"); die unless $dbh; $new = new CGI; $from_address = param('from_address'); $to_address = param('to_address'); $subject = param('subject'); $body = param('body'); $email = param('email'); if (!($from_address) | | !($body) | | !($subject)) { print "Content-Type: text/htmlnn"; print "<h2>Please go back and complete the form.</h2>n"; exit; } if ($news1) { $list_q = "SELECT email FROM users where news1='Yes'"; } if ($news2) { $list_q = "SELECT email FROM users where news2='Yes'"; } ###################################### # Connecting to SQL to grab the event ###################################### $query=$dbh->prepare($list_q); $query->execute; $rows=$query->rows; while(@user = $query->fetchrow) { if (!$user[0]) { # next; $sendmail; } ################## ## Mail::Sender ## ################## sub sendmail { use Mail::Sender; $sendmail = new Mail::Sender({from => "$from_address"}) | | die &fatal_error("Mail::Sender::Error"); $sendmail->Open({to => "$user[0]", subject => "$subject"); $sendmail->SendLine("$body"); $sendmail->Close; } and print "Content-Type: text/htmlnn"; if ($news1) { print "<h2>Your message has been sent.</h2>"; } print "Context-Type: text/htmlnn"; if ($news2) { print "<H2>Your message has been sent.</H2>"; } ----------------------------------------- Here's the errors that Apache is giving out: [Wed Aug 16 14:36:56 2000] mailsender: syntax error at /www/cgi-bin/mailsender line 60, near ""$subject")" [Wed Aug 16 14:36:56 2000] mailsender: syntax error at /www/cgi-bin/mailsender line 65, near "and" [Wed Aug 16 14:36:56 2000] mailsender: Missing right curly or square bracket at /www/cgi-bin/mailsender line 73, at end of line [Wed Aug 16 14:36:56 2000] mailsender: Execution of /www/cgi-bin/mailsender aborted due to compilation errors. |
|
#2
|
||||
|
||||
|
Alot of mistakes are their in the script. $sendmail->Open({to => "$user[0]", subject => "$subject"); In this line you haven't closed "}". also while loop has not closed.. << $sendmail; >> This also is wrong .it should be &sendmail; i have changed few things...just try and edit again.. #!/usr/local/bin/perl -w use CGI qw(:standard); use CGI::Carp qw/fatalsToBrowser/; use DBI; use Mail::Sender; $drh = DBI->install_driver( 'mysql' ); $dbh=$drh->connect("DBName","User","Pass"); die unless $dbh; $new = new CGI; $from_address = param('from_address'); $to_address = param('to_address'); $subject = param('subject'); $body = param('body'); $email = param('email'); if (!($from_address) | | !($body) | | !($subject)) { print "Content-Type: text/htmlnn"; print "<h2>Please go back and complete the form.</h2>n"; exit; }else{ if ($news1) { $list_q = "SELECT email FROM users where news1='Yes'"; } if ($news2) { $list_q = "SELECT email FROM users where news2='Yes'"; } ###################################### # Connecting to SQL to grab the event ###################################### $query=$dbh->prepare($list_q); $query->execute; $rows=$query->rows; if ($rows>0){ while(@user = $query->fetchrow) { if (!$user[0]) { # next; &sendmail; } print "Content-Type: text/htmlnn"; if ($news1) { print "<h2>Your message has been sent.</h2>"; }elsif ($news2) { print "<H2>Your message has been sent.</H2>"; } } } ################## ## Mail::Sender ## ################## sub sendmail { use Mail::Sender; $sendmail = new Mail::Sender({from => "$from_address"}) | | die &fatal_error("Mail::Sender::Error"); $sendmail->Open({to => "$user[0]", subject => "$subject"}); $sendmail->SendLine("$body"); $sendmail->Close; } Good Luck!!! ------------------ SR - webshiju.com www.jobxyz.com-IT Career Portal ezipindia.com--WebStudio "The fear of the LORD is the beginning of knowledge..." |
|
#3
|
|||
|
|||
|
>>$sendmail = new Mail::Sender({from => "$from_address"}) | | die &fatal_error("Mail::Sender::Error");
Make sure you also have a "sub fatal_error" in your script. Something like this... sub fatal_error { $fatal_error = $_[0]; print "Content-type: text/htmlnn"; print "<h1 align=center>$fatal_error</h1>n"; exit; } |
|
#4
|
|||
|
|||
|
Great, that worked fine. I appreciate it guys.
![]() Loki |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > More problems with sending mail..... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|