in reply to Hand-rolled CGI mailto

People have explained what's wrong with your web code. Now I'll explain what's wrong with your mail code!

An SMTP message is made up of a series of headers, followed by a blank line, followed by the body of the message. Just putting a blank line in your Perl source code is not sufficient to put a blank line in the e-mail message...

By and large, you should avoid talking to sendmail directly. Use a Perl module instead to save you from having to worry about the nitty-gritty details. Here's how you could send the message with Mail::Sendmail:

use Mail::Sendmail; sendmail( To => $to, From => $from, Subject => $subject, Body => <<END_OF_BODY, Name: $name EMail: $email Address_line_1: $address1 Address_line_2: $address2 City: $city State: $state Zip: $zip Home_Phone: $homephone Work_Phone: $workphone Type_of_Business: $business Goals: $goals Comments: $comments END_OF_BODY ) or print "Failed to send message [$subject] to [$to]: $Mail::Sendmai +l::error\n";

Hope this helps.

update: corrected a silly bug in the heredoc syntax (forgot the <<).

Replies are listed 'Best First'.
Re: Re: Hand-rolled CGI mailto (use a module to send e-mail)
by bradcathey (Prior) on Dec 17, 2003 at 14:56 UTC
    Grinder is right on with this advice. I went through this same learning curve earlier in the week in this node and am loving Mail::Sendmail, thanks to him.

    You use of $formdata looks strangely like what I used to do when using someone's handrolled form parser (this bad practice is propagated in The Perl and CGI Visual QuickStart Guide for one). Don't do it! Listen to the good monks here. Use CGI!!! And if you are doing much web work, I have one module for you: HTML::Template. It's wonderful.

    You will see lots of encouragement to use strict; use warnings; etc. All a bit daunting at first, but learnable with the help of the folks here at the monastery. I have found lurking around here invaluable.

    You will also see lots of references to Learning Perl and Programming Perl. I also recommend Programming CGI (all aforementioned are O'Reilly books).

    —Brad
    "A little yeast leavens the whole dough."
Re: Re: Hand-rolled CGI mailto (use a module to send e-mail)
by Gerard (Pilgrim) on Dec 18, 2003 at 01:53 UTC
    An SMTP message is made up of a series of headers, followed by a blank line, followed by the body of the message. Just putting a blank line in your Perl source code is not sufficient to put a blank line in the e-mail message...

    This is correct, but he does have two \n 's after his subject line, which would be sufficent. Otherwise excellent advice.
    Regards,

    Gerard
Re^2: Hand-rolled CGI mailto (use a module to send e-mail)
by Nkuvu (Priest) on Dec 17, 2003 at 17:43 UTC
    Any particular advantage to Mail::Sendmail as opposed to Mail::Mailer? I started using Mail::Mailer after reading the FAQ on mail (I'm not sure which section it's in, I found it via peroldoc -q mail). I'm not familiar enough with either module to make a decent comparison.