CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
getting this script to send e-mail in rich text + a confirmation e-mail

 



nitrogen_widget
Deleted

Nov 6, 2000, 12:56 PM

Post #1 of 6 (618 views)
getting this script to send e-mail in rich text + a confirmation e-mail Can't Post

hello all, I have a form processing script that I have off the net. It has a custom CGI.pm file with it. I'm using it for an online application. The boss wants it in html so its easier to read & a confirmation e-mail sent. When I run the script I get the actual code printed out in the e-mail (the HTML tags). I think it may be the CGI.pm file. I'd like to use the full CGI.pm module but I can't figure out how to use it.
Right now the script also requires certain form fields & I don't want to loose that.
Heres the script
& the CGI.pm file
#!/usr/bin/perl

require 'cgi.pm'; # Location of cgi.pm on your server


$subject="subject";
$sender="sender\@sender.com";
$recipient = 'recipient@recipient.net';

$time = localtime(time);


# required fields

%in = ();
&ReadParse(%in); # Parse the data submitted by the user

if (($in{'first_name'}) && ($in{'last_name'}) && ($in{'Phone2'})) {


# mail part
$mailprog = "/usr/sbin/sendmail"; # Insert location of sendmail on your sever

open (MAIL, "|$mailprog -t") | | die "Can't open $mailprog!\n";
print MAIL "To: $recipient <$recipient>\n";

print MAIL "From: $in{'Email'}\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n\n";
print MAIL "<center><b>Todays Date: $time\n\n</b></center> <br>";
print MAIL "\n\n";
print MAIL " <b>Hello,</b><br>\n ";
print MAIL " <i> rich text e-mail.</i><br> \n";
print MAIL " <font size=3> large text</font> <br> Andrew \n";
print MAIL "\n\n" ;
close (MAIL);

# thankyou page
print "Location: http://www.thankyou.html\n\n";


exit(0); # exit out of the script

} # end if statement


# print page if required fields wern't filled out

else {

print "Content-type: text/html \n\n";

print <<EOL;
<HTML>
<BODY>
Please make sure that the following fields all have valid information: <BR><BR>

<LI> <BR>
<LI> Comments <BR>
<LI> <BR><BR>

Please press the 'back' button in your browser to complete the form.
</body>
</html>
EOL
;

} # end else statement

# end of form


Here is the customized CGI.pm file

#!/usr/bin/perl

# The following code has been modified.

# Copyright 1996 (c) Steven Brenner

sub ReadParse {

local (*in) = @_ if @_;

local ($i, $key, $val);

# Read in text

if ($ENV{'REQUEST_METHOD'} eq "POST") {

read(STDIN,$in,$ENV{'CONTENT_LENGTH'});

}

else {

$in = $ENV{'QUERY_STRING'};

if (!$in) {

($in = $ENV{'PATH_INFO'}) =~ s/^\///;

}

}

@in = split(/&/,$in);

foreach $i (0 .. $#in) {

# Convert plus's to spaces

$in[$i] =~ s/\+/ /g;

# Split into key and value.

($key, $val) = split(/=/,$in[$i],2); # splits on the first =.

# Convert %XX from hex numbers to alphanumeric

$key =~ s/%(..)/pack("c",hex($1))/ge;

$val =~ s/%(..)/pack("c",hex($1))/ge;

# Associate key and value

$in{$key} .= "\0" if (defined($in{$key}));

# \0 is the multiple separator

$in{$key} .= $val;

}

return length($in);

}

1;

Any help would be appreciated.


------------------


[This message has been edited by nitrogen_widget (edited 11-06-2000).]


sleuth
Enthusiast / Moderator

Nov 6, 2000, 2:43 PM

Post #2 of 6 (618 views)
Re: getting this script to send e-mail in rich text + a confirmation e-mail [In reply to] Can't Post

 
Hello, Cure has answered this question before and I also used his code and it works great for send html email. His first post here
http://www.perlguru.com/forum/Forum2/HTML/000278.shtml

Is what I found to work perfectly.

Sleuth


sleuth
Enthusiast / Moderator

Nov 6, 2000, 2:47 PM

Post #3 of 6 (618 views)
Re: getting this script to send e-mail in rich text + a confirmation e-mail [In reply to] Can't Post

 
Sorry, forgot about your second question.

You can turn this code you used to send your confirmation email

open (MAIL, "|$mailprog -t") | | die "Can't open $mailprog!\n";
print MAIL "To: $recipient <$recipient>\n";

print MAIL "From: $in{'Email'}\n";
print MAIL "Subject: $subject\n\n";
print MAIL "Content-type: text/html\n\n";
print MAIL "<center><b>Todays Date: $time\n\n</b></center> <br>";
print MAIL "\n\n";
print MAIL " <b>Hello,</b><br>\n ";
print MAIL " <i> rich text e-mail.</i><br> \n";
print MAIL " <font size=3> large text</font> <br> Andrew \n";
print MAIL "\n\n" ;
close (MAIL);

And about cgi.pm, You won't have to can it.

Sleuth

P.S. Did you ever get that zipcode redirectional script working ok?


nitrogen_widget
Deleted

Nov 7, 2000, 3:03 PM

Post #4 of 6 (618 views)
Re: getting this script to send e-mail in rich text + a confirmation e-mail [In reply to] Can't Post

OK everyone thanks alot. I have everything running fine except when the e-mailed application is recieved theres a random "!" (exclamation point) that pops up in one field each time the script is run.
Heres an example "Salary: 2.! 50/hr "
Each time the form is reloaded it pops up in a new spot.

I can't wouldn't even know where to begin.
Please help. Heres my script

#!/usr/bin/perl

require 'cgi.pm'; # Location of cgi.pm on your server

$subject="Online Application";
$sender="app\@application.com";
$recipient = 'recipient@recipient.net';

$time = localtime(time);

# Please replace the required_field1, required_field2, #
# etc. below with the appropriate field #
# names specified in the HTML of your form. #
###############################################################

%in = ();
&ReadParse(%in); # Parse the data submitted by the user

if (($in{'first_name'}) && ($in{'last_name'}) && ($in{'Phone2'})) {


###############################################################
# Call the SendMail function! #
# Do not modify the following code, except where it says #
# "SUBJECT". #
# Please insert the subject in quotes that you wish to appear #
# in the e-mail message. #
# Make sure the variable mailprog matches the location of #
# sendmail on your server. (Ex. type 'which sendmail') #
###############################################################

$mailprog = "/usr/sbin/sendmail"; # Insert location of sendmail on your sever

open (MAIL, "|$mailprog -t") &#0124; &#0124; die "Can't open $mailprog!\n";
print MAIL "To: $recipient\n";
# print MAIL "Bcc: Webmaster\@BuffNET.net\n";
print MAIL "From: $sender\n";
# print MAIL "From: $in{'Email'}\n";
print MAIL "Subject: $subject\n";
print MAIL "Content-type: text/html\n";
print MAIL "\n\n";
print MAIL "<center><b>Date: $time</b></center>";
print MAIL "<center><b>$in{first_name} $in{last_name}</b></center>";
print MAIL "<center><b>SSN: $in{SSN22}</b></center>";
print MAIL "<center><b>$in{Address3}</b></center>";
print MAIL "<center><b>$in{Address2}</b></center>";
print MAIL "<center><b>$in{City}, $in{state} $in{zip}</b></center>";
print MAIL "<center><b>$in{Phone2}</b></center>";
print MAIL "<center><b>$in{Email}</b></center><br>";
print MAIL "<b>Job Desired:</b> $in{installer_technicians}, $in{sales}, $in{customer_service}, $in{office_staff}<br>";
print MAIL "<b>Related Experiance:</b> $in{related_experience}<br>";
print MAIL "<b>Date I Can Start:</b> $in{date} <b>Salary Desired:</b> $in{salary5}";
print MAIL "<b>Am I Currently Employed? :</b> $in{employed}<br>";
print MAIL "<center><b>EDUCATION</b></center>";
print MAIL "<b>High School:</b> $in{high_school} <b>Years:</b> $in{high_school_years} <b>Graduate:</b> $in{High_School_diploma} <b>Subjects:</b> $in{high_school_subjects}<br><br>";
print MAIL "<b>College:</b> $in{college} <b>Years:</b> $in{college_years2} <b>Graduate:</b> $in{college_diploma2} <b>Subjects:</b> $in{college_subject}<br><br>";
print MAIL "<center><b>FORMER EMPLOYERS</b></center>";
print MAIL "<b>Employer1:</b> $in{Employer1} <b>Address:</b> $in{Employer_address1}<br>";
print MAIL "<b>From:</b> $in{datestart1} <b>To:</b> $in{dateend1}<br>";
print MAIL "<b>Salary:</b> $in{salary1} <b>Position:</b> $in{position1}<br>";
print MAIL "<b>Reason For Leaving:</b> $in{Why_you_left1}<br><br>";
print MAIL "<b>Employer2:</b> $in{Employer2} <b>Address:</b> $in{Employer_address2}<br>";
print MAIL "<b>From:</b> $in{datestart2} <b>To:</b> $in{dateend2}<br>";
print MAIL "<b>Salary:</b> $in{salary2} <b>Position:</b> $in{position2}<br>";
print MAIL "<b>Reason For Leaving:</b> $in{Why_you_left2}<br><br>";
print MAIL "<b>Special Skills:</b> $in{special_skills}<br><br>";
print MAIL "<center><b>END APPLICATION</b></center>";
print MAIL "\n\n";
close (MAIL);
#send out confirmation E-mail
open (MAIL, "|$mailprog -t") &#0124; &#0124; die "Can't open $mailprog!\n";
print MAIL "To: $in{'Email'}\n";
print MAIL "From: $sender\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$time\n";
print MAIL "Your online application has been recieved\n";
print MAIL "A representative will contact you within the next business day\n";
print MAIL "Thank you\n";
print MAIL "\n\n";
close (MAIL);

# Thankyou page
print "Location: http://thankyou.html\n\n";


exit(0); # exit out of the script

} # end if statement


###############################################################
# The user did NOT submit sufficient information! #
# This else statement will take them to an HTML page #
# that basically says you missed the following required #
# fields, please press the 'back' button in your browser. #
# Please insert the names of the required fields. #
###############################################################

else {

print "Content-type: text/html \n\n";

print <<EOL;
<HTML>
<BODY>
Please make sure that the following fields all have valid information: <BR><BR>

<LI> First Name <BR>
<LI> Last Name <BR>
<LI> Phone Number <BR><BR>

Please press the 'back' button in your browser to complete the form.
</body>
</html>
EOL
;

} # end else statement

#end form




------------------


sleuth
Enthusiast / Moderator

Nov 8, 2000, 11:11 AM

Post #5 of 6 (618 views)
Re: getting this script to send e-mail in rich text + a confirmation e-mail [In reply to] Can't Post

 
You got me with that one, Your code has no reason to generate a ! in any field at random like that.

Sleuth


nitrogen_widget
Deleted

Nov 8, 2000, 11:52 AM

Post #6 of 6 (618 views)
Re: getting this script to send e-mail in rich text + a confirmation e-mail [In reply to] Can't Post

It may be my little e-smith server. I put it on another server & I saw the problem the first time i ran it then not since. It seemed each time i ran it the ! moved down a few lines then diapeared.

Thanks anyway

------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives