#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Norman, OK, USA
    Posts
    12
    Rep Power
    0
    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

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    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?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Norman, OK, USA
    Posts
    12
    Rep Power
    0
    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


  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    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).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Charleston, SC, USA
    Posts
    10
    Rep 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]
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>(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).]
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Norman, OK, USA
    Posts
    12
    Rep Power
    0
    Thanks for all the help

    -Loki
  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Norman, OK, USA
    Posts
    12
    Rep Power
    0
    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
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    16
    $body would all be on one line untill $body has n's in it:

    $body="Line 1n Line2";
  18. #10
  19. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>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");
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Norman, OK, USA
    Posts
    12
    Rep Power
    0
    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.


IMN logo majestic logo threadwatch logo seochat tools logo