Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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:
  #1  
Old August 8th, 2000, 10:24 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
Hello everyone,

I'm back again with another problem.

Here's what I've got:

A user comes to the site, wanting to sign-up
for A, B, and(or) C news letter.
They fill-out and submit the questions which
are stored in a mysql database.

Now, the editor (not very computer savy) has an address they can pull up with their browser, click which newsletter (news1 or news2) they will be submitting to,
fill in the body with whatever it is they will be sending to everyone signed up to receive this specific email, and click submit. Once submitted, it searches the db
for all rows that "yes" in the news1 (and/or) news2 field, extracts the email addy, and sends the email to that list.

The Problem: It's not working, and I'm not sure why.

The Code for the emailer:

#!/usr/local/bin/perl -w

$mailprog = '/bin/mailx';

use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;
use DBI;
use Mail::Sender

$drh = DBI->install_driver( 'mysql' );
$dbh=$drh->connect("DBName","User","PassWd");
die unless $dbh;

$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";
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;
}
## Mail::Sender
ref ($sender = new Mail::Sender({from => '"$from_address"',smtp => 'mail.oklahoman.com'})) or die "$Mail::Sender::Errorn";

(ref ($sender->MailMsg({to =>'"$user[0]"', subject => '"$subject"', msg => "$body"}))
and
print "Content-Type: text/htmlnn";
if ($news1) {
print "<h2>Your message has been sent.</h2>";
}
if ($news2) {
print "<H2>Your message has been sent.</H2>";
}


Thank you in advance for any help you may be able to offer.

-Loki


Reply With Quote
  #2  
Old August 8th, 2000, 01:16 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
All these modules and libraries are making my head spin!

With the exception of the DB one, these are all really a waist of time. (even the DB one is if you're willing to make this up out of flat file databases.. which would be going backwards in evolution).

But to be honest with you (I didn't read the script in much detail), I don't see anything wrong with this. But it could be all these steps that get skipped (using the modules) that are trowing me off.

Are you getting an error or what?

Reply With Quote
  #3  
Old August 8th, 2000, 01:34 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
I get an Internal Server Error from Apache:
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator,
blah@blah.com and inform them of the time
the error occurred, and anything you might
have done that may have caused the error.
More information about this error may be
available in the server error log.

using tail -f on the server error log, I get:

[Tue Aug 8 13:29:42 2000] mailsender: Name "main::to_address" used only once: possible typo at /www/cgi-bin/mailsender line 14.
[Tue Aug 8 13:29:42 2000] mailsender: Name "main::rows" used only once: possible typo at /www/cgi-bin/mailsender line 38.
[Tue Aug 8 13:29:42 2000] mailsender: Name "main::email" used only once: possible typo at /www/cgi-bin/mailsender line 17.
[Tue Aug 8 13:29:42 2000] [error] [client 127.0.0.1] Premature end of script headers: /www/cgi-bin/mailsender



Reply With Quote
  #4  
Old August 8th, 2000, 02:56 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
Ah, that last one's the only one that counts.
You need to have this somewhere in your script:
#####
print "Content-type: text/htmlnn";
#####

This usually come right before something is given back to the viewer, like a conformation screen.

[This message has been edited by JonLed (edited August 08, 2000).]

Reply With Quote
  #5  
Old August 8th, 2000, 03:29 PM
goBoating goBoating is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Charleston, SC, USA
Posts: 10 goBoating User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The 'Premature End of ...' complaint can occor for any number of reasons. Perl buffers its output. Consequently, if while the 'content-type' line or some portion of it is still in the output buffer, the code blows up, then the complete header does not make it to the browser.

Like JonLed, I have not taken time to completely critique the syntax. However, it appears to me that you have spaces between your pipes where you are trying to do 'or'.

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
if (!($from_address) | | !($body) | | !($subject)) {
[/code]

Reply With Quote
  #6  
Old August 8th, 2000, 04:45 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>(ref ($sender->MailMsg({to =>'"$user[0]"', subject => '"$subject"', msg => "$body"}))

Don't use Mail::Sender that way..plus, you left out the "open".
Anyway, here is an example of using Mail::Sender...

sub sendmail {
use Mail::Sender;
#don't need to specify "smtp" at all. Sender.pm will determine it for you.
$sendmail = new Mail::Sender({from => "$from_address"}) | | die &fatal_error("$Mail::Sender::Error");
#Assuming $user[0] gives you the email address
$sendmail->Open({to => "$user[0]", subject => "$subject"});
#Don't use MailMsg and msg, break each lines like this..
$sendmail->SendLine("Hello,");
$sendmail->SendLine;
$sendmail->SendLine("Thank you for posting a news letter");
$sendmail->SendLine;
$sendmail->SendLine("----");
$sendmail->SendLine("Loki");
# You left out the following line
$sendmail->Close;
}
Also, don't use Mail::Sender if your host allows you to use sendmail or qmail. I had this project few years ago which that host didn't allow me to use sendmail. That was the only time I was forced to use Mail::Sender.

Let me add this..
To add the user's name within the "to" section, you can do something like this..

$sendmail->Open({to => "$first_name $last_name <$email>", subject => "$subject"});

You also don't need to specify $mailprog = '/bin/mailx'; to use Mail::Sender.

[This message has been edited by freebsd (edited August 08, 2000).]

Reply With Quote
  #7  
Old August 9th, 2000, 10:21 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
Thanks for all the help

-Loki

Reply With Quote
  #8  
Old August 9th, 2000, 10:41 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
One question,

at concerning the post by freebsd,
at $sendmail->SendLine();

if I use $sendmail->SendLine("$body");

Will that place the $body of the e-mail on
one line, or on multiple lines?

or should I go ahead and use msg, since the body of the msg is typed out in the form?

-Loki

Reply With Quote
  #9  
Old August 9th, 2000, 11:59 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
$body would all be on one line untill $body has n's in it:

$body="Line 1n Line2";

Reply With Quote
  #10  
Old August 9th, 2000, 01:01 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>Will that place the $body of the e-mail on
one line, or on multiple lines?

That has less to do with Sender.pm. It doesn't matter whether you use "msg" or "SendLine", it's all about the textarea box of your form. Just be sure not to wrap line. If you do so, people tend to continue typing without pressing ENTER. That is, no n.

>>if I use $sendmail->SendLine("$body");

Yes, you can do that.


$sendmail->SendLine("Hello,");
$sendmail->SendLine;

is equivalent to..

$sendmail->SendLine("Hello,n");

Reply With Quote
  #11  
Old August 9th, 2000, 01:56 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
Great! So, as long as I don't use word wrap in the in the input type of the form, I should be set.

Thanks.


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > online email sending.

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap