bullweivel has asked for the wisdom of the Perl Monks concerning the following question:

Well what im trying to do is create a form and once the person hits submit on the form it goes to a CGI-Perl Script and sends out a email to the shipping department so that they know to send out a demo. Anyways I have run into a problem, number one being lack of PERL knowledge. So i thought at first I had found the answer to my problems and I figured i would play with some PERL and tweak some examples to my specs. Here is the example i have found that I havent been able to get to work: use strict; use Net::SMTP; my $globalMailServer = "127.0.0.1"; { sendmail ('JoeCool@somewhere.com', # put real e-mail address + here 'JoeCoolio', # put your real name here + 'shipping@somewhere.com', # put dest e-mail address + here 'Shipping Department', # put dest name here 'You the man', # subject 'This probably wont work, but oh well.'); # message } sub sendmail { @_ == 6 or die "Improper number of arguments"; my ($fromemail, $fromname, $toemail, $toname, $subject, $message) += @_; my $smtp = 0; $smtp = Net::SMTP->new($globalMailServer) or die "Can't connect to + mail server named '$globalMailServer'\n"; $smtp->mail ($fromemail); $smtp->to ($toemail); $smtp->data (); $smtp->datasend ("To: $toname\n"); $smtp->datasend ("From: $fromname\n"); $smtp->datasend ("Subject: $subject\n"); $smtp->datasend ("\n"); $smtp->datasend ($message); $smtp->dataend (); $smtp->quit; } NOTE: Originaly there was a path to the /Usr/bin/perl i belive it was, well i took that out because im under the impression it is not needed on a NT system running IIS 5. Also i tweaked this a little bit for this post. In the running example there are valid email adddresses and also valid SMTP server. The SMTP server im using is the one that comes with IIS 5, and currently im using that on several other projects that are running ASP's and Cold Fusion on the same server without any problems. I would imagine that in the errors im getting that the SMTP server is not the problem though. THE ERROR: (Get this if i run the program or run PERL -W filename)C:\>perl -w mailtest.pl String found where operator expected at mailtestorg.pl line 9, near "here 'JoeCoolio'" (Do you need to predeclare here?) String found where operator expected at mailtestorg.pl line 13, near "here 'Shipping Department'" (Do you need to predeclare here?) syntax error at mailtestorg.pl line 9, near "here 'JoeCoolio'" Execution of mailtest.pl aborted due to compilation errors. END OF ERROR OUTPUT- Okay so that is all of it in a nutshell. The original article i read stated that i should do a perl -e "user Net::SMTP" which i did and had received no errors. Any ideas? What am i doing wrong with this? Also please remember i am very new to PERL, so be kind :) Thanks in advance. twarfield@astcorp.com

Replies are listed 'Best First'.
Re: NT and Email
by chromatic (Archbishop) on Sep 24, 2000 at 02:19 UTC
    Really simple. Here's the error message:
    String found where operator expected at mailtestorg.pl line 9, near "here 'JoeCoolio'" (Do you need to predeclare here?)
    'here' in that context is supposed to be part of the comment, but Perl's not picking it up as part of the comment. That's probably because there's a newline right before it.

    Make sure that there are no newlines in your comments, and I'm confident that this error will disappear.

    If you're really having trouble understanding Perl warnings and errors, put 'use diagnostics;' at the start of your script, near 'use strict;'. It'll save you looking things up in perldiag yourself.

Re: NT and Email
by bullweivel (Initiate) on Sep 23, 2000 at 23:04 UTC
    Well that came out all messed up in formating..not sure why. To see a example of the code look at this link: http://www.perlmonks.com/index.pl?node_id=23303&lastnode_id=23299 I am also going to contact jcwren about this and see what he has to say. Thanks again, Thomas
      Your posting problem is that you failed to put <code> tags around your </code>.

      use strict; use Net::SMTP; my $globalMailServer = "127.0.0.1"; { sendmail ('JoeCool@somewhere.com', # put real e-mail address here 'JoeCoolio', # put your real name here 'shipping@somewhere.com', # put dest e-mail address here 'Shipping Department', # put dest name here 'You the man', # subject 'This probably wont work, but oh well.'); # message } sub sendmail { @_ == 6 or die "Improper number of arguments"; my ($fromemail, $fromname, $toemail, $toname, $subject, $message) += @_; my $smtp = 0; $smtp = Net::SMTP->new($globalMailServer) or die "Can't connect to + mail server named '$globalMailServer'\n"; $smtp->mail ($fromemail); $smtp->to ($toemail); $smtp->data (); $smtp->datasend ("To: $toname\n"); $smtp->datasend ("From: $fromname\n"); $smtp->datasend ("Subject: $subject\n"); $smtp->datasend ("\n"); $smtp->datasend ($message); $smtp->dataend (); $smtp->quit; }