I'm trying to get an email generated when a form is processed. This is my first stab at such. It's not working for some reason. When I comment out the lines concerning the email generation, it works fine. The problem apparently lies somewhere in that section of the code, but I'm not sure just what the issue is.

#!/usr/bin/perl 
#trialSubscription.cgi


print "Content-type: text/html\n\n";
use CGI qw(:standard);
use Mail::Sendmail;
use strict;


#var declarations
my ($firstName, $lastName, $email, $street, $city, $state, $zip, $msg, %mail);


#var values
$firstName = param('firstName');
$lastName = param('lastName');
$email = param('email');
$street = param('street');
$city = param('city');
$state = param('state');
$zip = param('zip');


#create message to email
$msg = "$firstName $lastName would like to subscribe to a free 6 month trial of SGN Scoops.  His/her email address is $email. \n";
$msg = $msg . "The physical address is $street in $city, $state $zip.";


#create page
print <<endHtml;
<html>
<head>
<title>Thank you for subscribing</title>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center" /><font size="4" face="Arial">Thank you for subscribing, $firstName.<br />
Click <a href="index.html">here</a> to return to the SGN Scoops main page.</font></p>
</body>
</html>
endHtml


#send email
$mail{To} = 'kahaj@yahoo.com';
$mail{From} = $email;
$mail{Subject} = 'Trial Subscription Request';
$mail{Smtp} = 'mail.sgnscoops.com';
$mail{Message} = $msg;
sendmail(%mail);

In my previous post, I used an example from a text book. I've scoured the web and found various reccomendations on how to accomplish my goal. I've tried the following only to end up with a 500 error still. :( Any tips with this would be fantastic.

#!/usr/bin/perl 
#trialSubscription.cgi


use CGI qw(:standard);
use Mail::Sendmail;
use strict;


#var declarations
my ($firstName, $lastName, $email, $street, $city, $state, $zip, $msg, %mail);


#var values
$firstName = param('firstName');
$lastName = param('lastName');
$email = param('email');
$street = param('street');
$city = param('city');
$state = param('state');
$zip = param('zip');


#send email
open (MESSAGE,"| /usr/sbin/sendmail -t");
	print MESSAGE "To: kahaj\@yahoo.com\n";
	print MESSAGE "From: sgnscoops.com", reader\n";
	print MESSAGE "Subject: Trial Subscription Request \n\n";
	print MESSAGE "$firstName $lastName\n\n";
	print MESSAGE "$email\n\n";
	print MESSAGE "$street\n";
	print MESSAGE "$city, $state  $zip\n\n";
close MESSAGE;


#create page
print <<endHtml;
<html>
<head>
<title>Thank you for subscribing</title>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p align="center" /><font size="4" face="Arial">Thank you for subscribing to our free trial offer, $firstName.<br />
We hope that you enjoy the all-new SGN Scoops!<br />
Click <a href="index.html">here</a> to return to the SGN Scoops main page.</font></p>
</body>
</html>
endHtml

replace these lines:

#create page
print <<endHtml;

replace with:

#create page
print header;
print <<endHtml;

"header" is a function of the CGI modules ":standard" functions and will print the http header which is required before printing anything else to the browser. I could have sworn I already told you that on another forum but maybe I am confused.

If you did, I certainly don't recall it, but I won't swear that you didn't. At any rate, I changed that and it still says the same thing. My server's error log does say this:
"Premature end of script headers: /home/.../public_html/cgi-bin/trialSubscription.cgi"

I'm doing some research to see what could cause this, but I'm finding a lot of different tips. I'm going to start trying them one by one to see how it goes (or how it doesn't go).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.