Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old August 16th, 2000, 02:51 PM
Loki Loki is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Norman, OK, USA
Posts: 12 Loki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Loki
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.


Reply With Quote
  #2  
Old August 16th, 2000, 09:44 PM
Shiju Rajan's Avatar
Shiju Rajan Shiju Rajan is offline
.Net Developer
Dev Shed Novice (500 - 999 posts)
 
Join Date: Feb 2000
Location: London
Posts: 987 Shiju Rajan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 9
Send a message via MSN to Shiju Rajan Send a message via Yahoo to Shiju Rajan

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..."

Reply With Quote
  #3  
Old August 16th, 2000, 10:49 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>$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;
}

Reply With Quote
  #4  
Old August 17th, 2000, 09:12 AM
Loki Loki is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Norman, OK, USA
Posts: 12 Loki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Loki
Great, that worked fine. I appreciate it guys.

Loki

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > More problems with sending mail.....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway