Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CGI and Mail

Status
Not open for further replies.

samesale

Programmer
Sep 15, 2003
133
0
0
US
I have written the following program to send e-mail to those who fill out a form. However, it does not send the subject and the e-mail address with the message. The same statements work in other programs. Please help.

$mailprog ='/usr/lib/sendmail';
$recipient ="sales\@test.com";
$subject = "sale";

open (MAIL, "| $mailprog $recipient") or die "Could not open Mailprogram:";

print MAIL "TO: $recipient\n";
print MAIL "FROM: $FORM{'email'}\n";
print MAIL "Subject : $subject\n";
print MAIL "Sale Site - Sale\n ";
print MAIL "Ad from $FORM{'name'} $FORM{'address'} $FORM{'city'}";
print MAIL "$FORM{'state'} $FORM{'zipcode'}.\n";
print MAIL "You are selling $FORM{'make'} model $FORM{'model'} with $FORM{'color'} color and $FORM{'mile'}";
print MAIL " miles year $FORM{'year'} for $d $FORM{'price'} with your description $FORM{'comment'}";
print MAIL " photo included $FORM{'photo'}\n";

close (MAIL);

$mailprog ='/usr/lib/sendmail';
$recipient ="sales\@test.com";

open (MAIL, "| $mailprog $FORM{'email'}") or die "Could not open Mailprogram:";

print MAIL "TO: $FORM{'email'}\n";
print MAIL "FROM: $recipient\n";
print MAIL "Subject : Sale\n";
print MAIL "For Sale\n";
print MAIL "On day and date: $today: $thismon-$mday-$year \n";
print MAIL "You have provided this information:\n";
print MAIL "Your name : $FORM{'name'}. Your address: $FORM{'address'} $FORM{'city'}\n";
print MAIL "$FORM{'state'} $FORM{'zipcode'}\n";
print MAIL "You phone : $FORM{'telephone'} to call you between $FORM{'time'} \n";
print MAIL "You are selling $FORM{'make'} model $FORM{'model'} with $FORM{'color'} color and $FORM{'mile'} miles of year $FORM{'year'} for $d $FORM{'price'} with your description $FORM{'comment'} \n";
print MAIL " \n";


close (MAIL);
 
Are the rest of your FORM variables being set?
--Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I'm not sure if these changes will help but maybe give them a go...

Code:
print MAIL "Subject : $subject\n";
print MAIL "Sale Site - Sale\n ";
print MAIL "Ad from $FORM{'nam...

1. remove the space before the 'colon' after subject
2. add a further newline after 'Sale'

Code:
print MAIL "Subject: $subject\n";
print MAIL "Sale Site - Sale\n\n";
print MAIL "Ad from $FORM{'nam...


Kind Regards
Duncan
 
Personally, I think yu should use CGI to parse your form fields rather than trying to parse hash/value pairs.

Code:
use CGI qw(param);
my $email = param("email");
my $namne = param("name");
my $address = param("address");
my $city = param("city");
my $state = param("state"); 
my $zipcode = param("zipcode");
my $telephone = param("telephone");
my $time = param("time");
my $make = param("make");
my $model = param("model");
my $color = param("color");
my $year = param("year");
my $price = param("price");
my $comment = param("comment");
my $photo = param("photo");
$mailprog ='/usr/lib/sendmail';
$recipient ="sales\@test.com";
$subject  = "sale";

open MAIL, "| $mailprog -i -t  or die "Could not open Mailprogram:";

print MAIL "TO: $recipient\n";
print MAIL "FROM: $email\n";
print MAIL "Subject: $subject\n";
print MAIL "Sale Site - Sale\n ";
print MAIL "Ad from $name $address $city\n";
print MAIL "$state $zipcode.\n";
print MAIL "You are selling  $make model $model with $color color and $mile";
print MAIL " miles year $year for $d $price with your description $comment";
print MAIL " photo included $photo\n";

close (MAIL);

open MAIL, "| $mailprog -i -t or die "Could not open Mailprogram:";

print MAIL "TO: $email\n";
print MAIL "FROM: $recipient\n";
print MAIL "Subject: Sale\n";
print MAIL "For Sale\n";
print MAIL "On day and date: $today: $thismon-$mday-$year \n";
print MAIL "You have provided this information:\n";
print MAIL "Your  name : $name.  Your address: $address  $city\n";
print MAIL "$state $zipcode\n";
print MAIL "You phone : $telephone to call you between $time \n";
print MAIL "You are selling $make model $model with $color color and $mile miles of year $year for $d $price with your description $comment\n\n";

close (MAIL);

Also, the open (MAIL... line might work if you remove the email address, like this:

Code:
open MAIL, "| $mailprog -i -t or die "Could not open Mailprogram:";

There's always a better way. The fun is trying to find it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top