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

Does anyone have any send mail code that would work for this code because I can't seem to get it working? If anyone else has any comments on the code could you please tell me to help me on my way. Thanks Perl monks
#!/usr/bin/perl -w use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; CGI::ReadParse(); print MAIL "$in{'Title'}\n"; print MAIL "$in{'Name'}\n"; print MAIL "$in{'Position'}\n"; print MAIL "$in{'School'}\n"; print MAIL "$in{'Address'}\n"; print MAIL "$in{'Suburb'}\n"; print MAIL "$in{'State'}\n"; print MAIL "$in{'PCode'}\n"; print MAIL "$in{'Email'}\n"; print MAIL "$in{'Tel'}\n"; print MAIL "$in{'Fax'}\n"; print MAIL "$in{'Att1'}\n"; print MAIL "$in{'Att2'}\n"; print MAIL "$in{'Att3'}\n"; print MAIL "$in{'Att4'}\n"; print MAIL "$in{'Att5'}\n"; print MAIL "$in{'Att6'}\n"; print MAIL "$in{'Att7'}\n"; print MAIL "$in{'Att8'}\n"; print MAIL "$in{'Att9'}\n"; print MAIL "$in{'Comments'}\n";

20030808 Edit by jeffa: Changed title from 'Sendmail '

Replies are listed 'Best First'.
Re: How do I send mail from a script?
by Limbic~Region (Chancellor) on Aug 08, 2003 at 04:26 UTC
    Nickd_69,
    Ok - I am likely going to receive some downvotes for being so harsh with you, but so be it. It doesn't appear that you are even beginning to make an effort here. In Premature end of script headers you asked this very question. I gave you advice here, and provided more advice as well as code here and here. You didn't take my advice nor did you come back to say what errors you ran into. So let me break it down step by step.
    #!/usr/bin/perl -w # This turns on warnings use strict; # This pragma will help you avoid common mistakes by enforcing commonl +y accepted "good" coding techniques use CGI; # This will allow you to redirect your web page once you send the emai +l use CGI::Carp qw(fatalsToBrowser); # This will put any fatal errors to your web page instead of to the no +rmal error log use Mail::Mailer; # This will allow you to send the email my $query = CGI->new(); # This creates a new CGI object. The redirect method will come after +we have sent the mail. my %DATA = $query->Vars; # This uses a method on the CGI object to stick all the form values i +nto the DATA hash for you my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'info@travancoresch.vic.edu.au', From => $DATA{Email}, Subject => 'Travancore School Professional Development' } ); # This will create a new object that we will use to send the email print $mailer "$DATA{Att1}\n"; print $mailer "$DATA{Att2}\n"; print $mailer "$DATA{Att3}\n"; # This will print to the email $mailer which is a file handle created +for you when you create the object. $mailer->close; # This sends the email print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html'); # This redirects the web page to the new desired location
    I am going to suggest you read the past replies I have sent to actually look at the comments I made and not just blindly copy and paste code. You have repeated the same mistakes.

    If you do all that and it still doesn't work - come back and tell us what errors you got - we will be glad to help.

    L~R

      Look I'm sorry for getting you so pissed off but I am only learning. I have gone through your code and I had already read all your comments and nearly all available info off this site. I now have the following script but the error I get in my error log is something like that CGI is not declared on line 8 and the script was aborted due to compilation errors. Could you just have a quick look? I know how frustrating newbies are but im slowly getting it!!
      #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; my $query = CGI->new(); my %DATA = $query->Vars; my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'info@travancoresch.vic.edu.au', From => $DATA{Email}, Subject => 'Travancore School Professional Development' } ); print $mailer "$DATA{Title}\n"; print $mailer "$DATA{Name}\n"; print $mailer "$DATA{Position}\n"; print $mailer "$DATA{School}\n"; print $mailer "$DATA{Address}\n"; print $mailer "$DATA{Suburb}\n"; print $mailer "$DATA{State}\n"; print $mailer "$DATA{PCode}\n"; print $mailer "$DATA{Email}\n"; print $mailer "$DATA{Tel}\n"; print $mailer "$DATA{Fax}\n"; print $mailer "$DATA{Att1}\n"; print $mailer "$DATA{Att2}\n"; print $mailer "$DATA{Att3}\n"; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');
Re: How do I send mail from a script?
by Aristotle (Chancellor) on Aug 08, 2003 at 02:42 UTC
    Hmm. You're writing to the filehandle MAIL, but you've never opened it. And by your use of Mail::Mailer, you don't want to. If you RTFM, you can basically just lift the SYNOPSIS straight into your script:
    $mailer = Mail::Mailer->new; $mailer->open(\%headers); print $mailer $body; $mailer->close;
    Adjust as needed.

    Makeshifts last the longest.

    A reply falls below the community's threshold of quality. You may see it by logging in.