how to set time

Discussion in 'Perl Misc' started by Peter, Feb 18, 2005.

  1. Peter

    Peter Guest

    Hello All,
    I'm a newbie and busy with a mailform.

    This mailform sent autoresponse mail.
    My question is if it possible to sent the autoresponse mail one or two days later after receiving the mail.


    I think it has to be change in this piece of code ?



    $offset = @_;
    $offset=$offset*86400;

    ($sec, $min, $hour, $dayofmonth, $mon, $year, $weekday, $dayofyear, $IsDST) = localtime(time + $offset);
    $year = $year + 1900;
    @months = ("JA", "FB", "MR", "AP", "MY", "JN", "JL", "AG", "SP", "Oc", "NV", "DE");
    $monthname = $months[$mon];
    @monthsnum = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
    $monthnamenum = $monthsnum[$mon];

    @monthsactual = ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    $monthnameactual = $monthsactual[$mon];


    @days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
    $dayname = $days[$weekday-1];

    ${'monthname'} = "$monthname";
    ${'monthnamenum'} = "$monthnamenum";
    ${'dayofmonth'} = "$dayofmonth";


    if ($hour > 12){
    $hourplus=$hour;
    $newhour = ($hourplus-12);
    $nightday = "PM";
    }else{
    $newhour=$hour;
    $nightday = "AM";
    }


    if ($min <= 9){
    $newmin = "0$min";
    }else{
    $newmin = "$min";
    }

    ${'hour'}=$newhour;
     
    Peter, Feb 18, 2005
    #1
    1. Advertising

  2. "Peter" <> wrote in
    news:J1oRd.22643$-ops.be:

    > I'm a newbie and busy with a mailform.
    >
    > This mailform sent autoresponse mail.
    > My question is if it possible to sent the autoresponse mail one or two
    > days later after receiving the mail.


    Yes, but that has nothing to do with the code you posted below.

    > I think it has to be change in this piece of code ?


    Is that a question or statement?

    ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">


    Please post plain text only.

    Sinan
     
    A. Sinan Unur, Feb 18, 2005
    #2
    1. Advertising

  3. Peter wrote:

    >
    > I think it has to be change in this piece of code ?


    Do it then. Why tell us?

    gtoomey
     
    Gregory Toomey, Feb 18, 2005
    #3
  4. Peter

    Peter Guest

    Hello Sinan,

    Yes it is a question because I really don't know how to change it.
    I want to sent the autoresponse 1 or 2 days later.

    Hereby I sent the send mail script.



    sub sdsmail {


    if ($send_email_results eq "1") {

    open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $MAIN_mail_send\n";
    if ($mail_ccto){
    print MAIL "Cc: $mail_ccto\n";
    }
    print MAIL "From: $formdata{'email'}\n";
    print MAIL "Subject: $formdata{'subject'}\n";
    print MAIL "The form below was submited by $formdata{'email'} form Ip
    address: $ENV{'REMOTE_ADDR'} on $monthnameactual $dayofmonth, $year at
    $newhour:$newmin $nightday \n";
    print MAIL
    "-------------------------------------------------------------------------\n\n";


    if (! $formdata{'sort'}) {


    for ($indexval = 0; $indexval < @formvalue; $indexval++) {
    ${'myname'} = $formname[$indexval];
    ${'myvalue'} = $formvalue[$indexval];


    if (${'myname'} eq "reply_subject"|| ${'myname'} eq "subject" ||
    ${'myname'} eq "sendreply" || ${'myname'} eq "required" || ${'myname'} eq
    "success_page" || ${'myname'} eq "message_format" || ${'myname'} eq
    "text_qualifier" || ${'myname'} eq "datafile" || ${'myname'} eq "outputfile"
    || ${'myname'} eq "sort" || ${'myname'} eq "data_format" || ${'myname'} eq
    "cc_to" || ${'myname'} eq "send_to" || ${'myname'} eq "plain_mesfile" ||
    ${'myname'} eq "html_mesfile" || ${'myname'} eq "error_page" || ${'myname'}
    eq "required_desc"){
    $dontrun = "1";
    }else{
    $dontrun = "";
    }

    ## CHECK PRINT BLANK FIELDS ##
    if ($PRNT_blankfields eq "2" && ! ${'myvalue'}) {
    $dontrun = "1";
    }

    if (! $dontrun){
    print MAIL "${'myname'}: ${'myvalue'} \n\n";
    }
    }

    }else{ ##ELSE IF NO SORT FIELD ##

    for ($numsort = 0; $numsort < @sortfields; $numsort++) {
    $sfield = $sortfields[$numsort];
    ${'sfieldvalue'} = $formdata{"$sfield"};
    ${'sfield'} = "$sfield";

    ## CHECK PRINT BLANK FIELDS ##
    if ($PRNT_blankfields eq "2" && ! ${'myvalue'}) {
    }else{

    print MAIL "${'sfield'}: ${'sfieldvalue'} \n\n";

    } ## END CHECK PRINT BLANK FIELDS ##

    }

    } ## END ELSE IF SORT FIELD ##

    close MAIL;

    } ## END IF SEND_EMAIL_RESULTS##

    if ($formdata{'sendreply'} eq "1"){



    use MIME::Lite;
    MIME::Lite->send("sendmail", "$mailprog -t -oi -oem");



    $msg = MIME::Lite->new(
    From => $mail_sendto,
    To => $formdata{'email'},
    Subject => $reply_subject,
    Type => $email_format,
    Data => $mime_body,
    "X-Arpidentifier:" => 12345

    );

    ########################################
    ## USE ATTACHEMENT ##
    ########################################

    if ($send_attachement eq "1"){

    $msg->attach(Type => $att_content_type,
    Encoding => $att_format->[1],
    Path => $att_path,
    Filename => $attachment_nm
    );

    }


    ######################################
    $msg->send;
    }

    }

    return 1;



    "A. Sinan Unur" <> wrote in message
    news:Xns96017EF248EBasu1cornelledu@132.236.56.8...
    > "Peter" <> wrote in
    > news:J1oRd.22643$-ops.be:
    >
    >> I'm a newbie and busy with a mailform.
    >>
    >> This mailform sent autoresponse mail.
    >> My question is if it possible to sent the autoresponse mail one or two
    >> days later after receiving the mail.

    >
    > Yes, but that has nothing to do with the code you posted below.
    >
    >> I think it has to be change in this piece of code ?

    >
    > Is that a question or statement?
    >
    >><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

    >
    > Please post plain text only.
    >
    > Sinan
     
    Peter, Feb 18, 2005
    #4
  5. Peter wrote:
    >
    > This mailform sent autoresponse mail.
    > My question is if it possible to sent the autoresponse mail one or two
    > days later after receiving the mail.


    Yes.

    > I think it has to be change in this piece of code ?


    <code snipped>

    No.

    To schedule the execution of code to a point of time in the future, you
    need a daemon. Check out

    perldoc -q daemon

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Feb 18, 2005
    #5
  6. "Peter" <> wrote in
    news:Q8qRd.30088$-ops.be:

    > Yes it is a question


    What is a question? Oh, you are top-posting, please do not do that.
    Please take this opportunity to read the posting guidelines for this
    group.

    > because I really don't know how to change it.
    > I want to sent the autoresponse 1 or 2 days later.
    >
    > Hereby I sent the send mail script.


    I think you are failing to realize the fundamental issue here. What is
    the point of expecting this script to wait for 172800 seconds to send
    the message?

    Instead, put the information in a table, have some kind of periodic task
    check the table for emails that need to be sent, and then send them.

    The script you posted is so badly written that just reading it is
    irritating.

    You are missing:

    use strict;
    use warnings;

    use CGI;

    > sub sdsmail {
    > if ($send_email_results eq "1") {


    Please make some effort to format the code you are posting properly.
    That will make your readers' lives easier and enable to them to help you
    more effectively.

    Where did $send_email_results come from?

    You would normally check a boolean by just using the simple

    if($send_email_results) {

    }

    No need for silly string comparisons.

    >
    > open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
    > print MAIL "To: $MAIN_mail_send\n";
    > if ($mail_ccto){
    > print MAIL "Cc: $mail_ccto\n";
    > }


    It looks like you are not using a hash when you should be:

    my %main = (
    mail_to => '',
    mail_cc => '',
    );

    etc.

    > print MAIL "From: $formdata{'email'}\n";
    > print MAIL "Subject: $formdata{'subject'}\n";


    It looks like you are using a home-made CGI parameter parsing thingie
    rather than CGI.pm. Most likely not a good idea.

    > print MAIL "The form below was submited by $formdata{'email'} form Ip
    > address: $ENV{'REMOTE_ADDR'} on $monthnameactual $dayofmonth, $year at
    > $newhour:$newmin $nightday \n";


    Whatever ...


    > for ($indexval = 0; $indexval < @formvalue; $indexval++) {
    > ${'myname'} = $formname[$indexval];
    > ${'myvalue'} = $formvalue[$indexval];


    Please don't do this.

    perldoc -q "variable name"

    I cannot even get myself to look at the code.

    > if (${'myname'} eq "reply_subject"|| ${'myname'} eq "subject" ||
    > ${'myname'} eq "sendreply" || ${'myname'} eq "required" || ${'myname'}


    I think a visit to <http://learn.perl.org/> is in order.

    > if (! $dontrun){


    unless( $dontrun ) {

    > use MIME::Lite;
    > MIME::Lite->send("sendmail", "$mailprog -t -oi -oem");


    WTF!!!? You just opened a pipe to sendmail above. *Now* it occurs to you
    to use MIME::Lite? Why not just use MIME::Lite and be done with it?

    Sinan.
     
    A. Sinan Unur, Feb 18, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. engsol
    Replies:
    2
    Views:
    993
    Dan Bishop
    Jan 26, 2004
  2. Replies:
    8
    Views:
    505
    Magnus Lycka
    Aug 5, 2005
  3. flamesrock
    Replies:
    8
    Views:
    552
    Hendrik van Rooyen
    Nov 24, 2006
  4. Ben
    Replies:
    2
    Views:
    401
  5. Phil Powell
    Replies:
    2
    Views:
    238
    Grant Wagner
    Sep 5, 2003
Loading...

Share This Page