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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Online Forms/other formats

Status
Not open for further replies.

Caden

Programmer
Dec 9, 2001
101
CA
Hi Tek-Tips.

So I made myself an online form and i'm using a Perl script to e-mail it to myself, got no problems there. Although when the information comes in, it's kind of like a data dump...I see it like this (as it should be really)

field name field answer
field name field answer
etc

I'm curious if there is a way (using other software or what not) to send online form information in a format of some sort. So as an example, I get a customer to send me financial information and I want to easily plug that into an excel spreadsheet. Or I want the information to come by way of a .pdf format...Any suggestions?

Thanks
Caden
 
Sure,

use NET::SMTP and send it to yourself as an html page. Then you can put it in just about any format you wish. If you want some sample code, let me know and I'll post it.

There's always a better way. The fun is trying to find it!
 
Sample code would be great, or a spot to learn about doing that...since i've never done it before.

Thanks for the help!
Caden
 
Okay - here it is:

Code:
#!/usr/bin/perl -T

use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use Net::SMTP; 
my $q = new CGI;
print $q->header();

[COLOR=blue]my $email = param("email_address");
my $subject = param("subject");
my $comment = param("comments");[/color]
my $mailprog = '[COLOR=red]/usr/sbin/sendmail[/color]';
my $ServerName = "smtp.[COLOR=red]your_site_name.com[/color]";
my $MailTo = "[COLOR=red]info\@your_site_name.com[/color]"; 
my $html_hdr = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
my $table1 = '<table width="60%" border="1" cellpadding="3" cellspacing="0">';
my $table2 = '<table width="100%" border="0" cellpadding="0" cellspacing="0">'; 
my $smtp = Net::SMTP->new($ServerName); 
die "Couldn't connect to server" unless $smtp;

$smtp->mail( $email );  
$smtp->to( $MailTo ); 

# Start the mail  
$smtp->data(); 
$smtp->datasend("To: $MailTo\n"); 
$smtp->datasend("From: $email\n");  
$smtp->datasend("Subject: $subject\n"); 
 
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("X-Mailer: your_site_name.com\n");
$smtp->datasend("X-Priority: 1\n");
$smtp->datasend("Content-Transfer-Encoding: quoted-printable\n");
$smtp->datasend("Content-type: text/html;  charset=ISO-8859-1\n\n"); 

# Send the body. 
$smtp->datasend("$html_hdr");
$smtp->datasend("<html><head>");
$smtp->datasend("<style>td\.a {font-family: arial,helvetica,verdana,san-serif; color: #000000; font-size: 12px}");
$smtp->datasend("</style></head>");
$smtp->datasend("<body> $table1");
$smtp->datasend("<tr><td colspan=\"2\">$table2");
$smtp->datasend("<tr><td class=\"a\">Email from: $email<br>Subject: $subject<br>Comments:</td></tr>");
$smtp->datasend("<tr><td height=\"10\"></td></tr>");
$smtp->datasend("<tr><td class=\"a\">$comment</td></tr></table></td></tr></table>");
$smtp->datasend("</body></html>\n");

# Send the termination string  
$smtp->dataend(); 

# Close the connection  
$smtp->quit();

The items in RED will be particular to you installation. You may have to verify with your hosting company the exact location of sendmail. The items in BLUE are the form field names that I'm sure you'll have to change. Play with this and you'll see how it works - it's the only way I've found to reliably send form data in a nice format.

Good luck!

There's always a better way. The fun is trying to find it!
 
Why not modify your PERL script to format the email in the way you want it?

Simply create a text string for the mail body using the data from the form.

 
Well, I started this discussion in the HTML forum because I was using HTML form's etc etc....


So, I have a problem, due to the host that I have to deal with for a time until the contract is over, and because this host sucks in such a big way I can't describe, I am stuck using their Perl script, and I can't adjust it, I can't even look at it. I've called them and they are totally clueless...is there a different solution that perhaps doesn't use a Perl script to send mail?

I've asked about ASP, and they don't support it, and i'm pretty sure they don't support iHTML...yes, I plan to change hosts as soon as possible
 
You can write your own server side script using PHP's mail() function... if your host supports PHP.

If not, and they don't support ASP either, then I guess you are stuck with their PERL script.

 
Alright, i'll give that a try.

Thanks for everything, this has been very helpful

Caden
 
Dan,

It was my fault... he asked about a script and rather than send him over to the Perl forum and answer it there, I put up a quick script to get him on his way. So, blame it on me - I apologize for any inconvenience it may have caused.

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