in reply to Contact Form 2

Untested code using Mail::Sendmail to give you an idea why using a module is far better :)

#!/usr/bin/perl -wT use strict; use CGI; use Mail::Sendmail; my $q = new CGI; my $name = $q->param("name"); my $email = $q->param("email"); my $message = $q->param("message"); # Config my $adminmail = "admin\@yoursite.com"; my $from = "whoever\@whatever.com"; my $subject = "enter subject here"; # End config my %mail = ( To => "$adminmail", From => "$from", Subject => "$subject", Message => "$message" ); sendmail(%mail) or die $Mail::Sendmail::error; print $q->redirect("thanks.html") or die "Can't find thanks.html: $!\n +";

Update: You should include Juerd's improvements listed below.

Replies are listed 'Best First'.
Re: Re: Contact Form 2
by Juerd (Abbot) on Mar 25, 2002 at 10:12 UTC

    "$adminmail"

    "$foo" is often very bad style. Consider it equal to '' . $foo . '', and just write it without quotes instead. Also, using single quotes allows you to write @ signs without escaping them (style advice: use double quotes only if you use their's specialties (read perlop)).
    You use %mail just once, and could have put that in the sub itself.

    In my style, this script would be:

    #!/usr/bin/perl -w # Well, to be completely honest: I don't like CGI.pm, and wouldn't use + it. # I will for now, because I'm just rewriting :) # You may have noticed I removed the tainting checks too. use strict; use CGI; use Mail::Sendmail; my $q = CGI->new(); # Updated as per particle's excellent observation my $name = $q->param('name'); # Note: used only once my $email = $q->param('email'); # Note: only used once my $message = $q->param('message'); # # Note: couldn't choose ;) # Config my $adminmail = 'admin@yoursite.com'; my $from = 'whoever@whatever.com'; my $subject = 'enter subject here'; # End config sendmail( To => $adminmail, From => $from, Subject => $subject, Message => $message ) or die $Mail::Sendmail::error; # Note: redirects should be absolute # (All modern browsers handle relative redirects, though) print $q->redirect('thanks.html') or die "Can't find thanks.html: $!\n +";

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

      umm... am i missing something, or should that my $q = CGI->; actually have a method call on the end, like my $q = CGI->new();?

      ~Particle ;Þ

Re: Re: Contact Form 2
by venimfrogtongue (Novice) on Mar 26, 2002 at 01:15 UTC
    Thanks Juerd! I do have one question for you. How do you specify the location of SENDMAIL in your version? I cannot see where you are actually telling it where it is, all you do is call sendmail. Thanks! sulfericacid