Results 1 to 5 of 5

Thread: CGI (Perl) - SMTP & Rediret Method

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    101

    Smile CGI (Perl) - SMTP & Rediret Method

    Good day !

    I have written the codes below and try to execute it. Theoritically, I suppose it works but it doesn't. I can't figure out what's wrong with my codes.

    The 2 problems are :

    1) It supposed to send back a mail to me but it doesn't. I used the code from Deitel & Deitel text book.

    2) It doesn't redirect to the page "default.asp" after executing the commands. May be I had put the code at the wrong place ?

    Anybody can look at my code and tell me what's wrong ?

    Thanks a lot !

    --------------------------------------------------------------------------------
    use Net::SMTP;
    use CGI qw/:standard/;

    my $to = "[email protected]";
    my $from = "[email protected]";
    my $subject = param ("SelectPurpose");
    my $message = param ("TxtMessage");
    my $mailserver = "hotmail.com";

    print header;
    print "<p>Your message has been sent !";
    print "Thank you for your contribution !";

    $smtp = Net::SMTP->new($mailserver);
    $smtp->mail($ENV{USER});
    $smtp->to("$to");
    $smtp->data();
    $smtp->datasend("To : $to \n");
    $smtp->datasend("From : $from \n");
    $smtp->datasend("Subject: $subject \n");
    $smtp->datasend("\n");
    $smtp->datasend("$message \n");
    $smtp->datasend();

    $smtp->quit;

    print redirect('../default.asp');

    -----------------------------------------------------------------------------

    Thanks again !

    SonicWave

  2. #2
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    1. Is hotmail.com a SMTP server that will accept connections from random ip addresses?

    2. You redirect with the HTTP headers, which need to be written before any HTML, so call the redirect first and don't bother printing the confimation message as they generally won't see it.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    101

    Wink Will the procedures after "Redirect" Will Be Executed ?

    Good day !

    I not sure whether Hotmail.com can be used or not, but that's what my tutor told me. I also confused.

    Besides, about "redirect". if I put it in the front, will the other functions / procedures after it will be executed ?

    If cannot , what should I do to modify my program so that, it will first have all functions executed, then only redirect to another page ?

    Thanks a lot !

    SonicWave

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    What the redirect is going to do is the same as going
    Code:
    print "Location: somepage.asp\n";
    just writing the correct HTTP header to standard output. So you can use all functions etc, but you have to write the HTTP headers first, then the HTML, etc, with the print statement, since anything "print"ed is being written to the web browser. Stuff that doesn't write to the web browser can go anywhere.
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    101

    Smile Thank You !

    Thank You !

    Now only I know

    I get your idea.

    Thanks again !

    SonicWave

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width