#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    Hello.

    I am trying to write a simple perl script that sends an email to someone. When I run it, it seems to work correctly (getting to the blank screen), but I never get the email. How long should I wait for the email (I have included the script below)?

    Thanks
    yoshi
    datera@datera.com http://www.datera.com

    =====================
    #!/usr/local/bin/perl -w
    print "Content-Type: text/htmlnn";

    use Net::SMTP;

    my $subject = "Subject: My test messagenn";
    my $message = <<EOM;
    Perl sent this message. Nifty, Eh?
    EOM

    $smtp = Net::SMTP->new('mailhost');
    $smtp->mail($ENV{USER});
    $smtp->to('datera@datera.com');
    $smtp->data();
    $smtp->datasend($subject);
    $smtp->datasend($message);
    $smtp->dataend();
    $smtp->quit();
    =====================
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    you don't need to use Net::SMTP for sending email. It is very simple from perl directly:

    # Path to your mail program
    $mailprogram = '/usr/lib/sendmail';

    open (MAIL, "|$mailprogram -t");
    print MAIL "To: $FORM{'email'}n";
    print MAIL "From: yosh@your.comn";
    print MAIL "Subject: Testingnn";
    print MAIL "Hello world<BR>";
    print MAIL "just testingn";
    # and next command sends email
    close (MAIL);
  4. #3
  5. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Yes, there's no reason to reinvent the wheel.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    108
    Rep Power
    15
    Thanks... but why won't this work?
    I do not have the capabilities to see the logfile, or run it with the command-line (I have a Mac). How could I work this so it works for the web?

    Thanks!
    yoshi
    datera@datera.com

    ========================

    #!/usr/local/bin/perl -w
    print "Content-Type: text/htmlnn";

    $mailprogram = '/usr/local/bin/sendmail';

    open (MAIL, "|$mailprogram -t");
    print MAIL "To: datera@datera.comn";
    print MAIL "From: yosh@your.comn";
    print MAIL "Subject: Testingnn";
    print MAIL "Hello world<BR>";
    print MAIL "just testingn";
    close (MAIL);
  8. #5
  9. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Here are 2 very important, basic rules that everybody should remember and will fix your script.

    1. All "@"'s that are not signifying and array should be "@".

    2. Always make sure the paths are right. I don't know if this effects your script, it varies from system to system. But the path to sendmail was wrong for my system.

    Here is the fixed code (with my path to sendmail):
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    #!/usr/local/bin/perl -w
    print "Content-Type: text/htmlnn";

    $mailprogram = '/usr/sbin/sendmail';

    open (MAIL, "|$mailprogram -t");
    print MAIL "To: datera@datera.comn";
    print MAIL "From: yosh@your.comn";
    print MAIL "Subject: Testingnn";
    print MAIL "Hello world<BR>";
    print MAIL "just testingn";
    close (MAIL);
    [/code]

    Let us know if it does/doesn't work.
  10. #6
  11. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>1. All "@"'s that are not signifying and array should be "@".

    Yes.

    Yoshi,
    If you define $admin_email like with double-quotes, you need to escape the @ character..

    $admin_email = "datera@datera.com";

    with single-quotes, that is not necessary, however.

    $admin_email = 'datera@datera.com';
  12. #7
  13. No Profile Picture
    ledjon
    Guest
    Devshed Newbie (0 - 499 posts)
    Good point, but Since the e-mail was directly inserted into the script, I just used the general rule :P.

IMN logo majestic logo threadwatch logo seochat tools logo