PDA

View Full Version : Send a form as an html formatted email


ivy
01-19-2003, 06:47 PM
Hi there

I have a rather large from on a web page. There are around 50 fields!!

After submitting the form to a perl/cgi script, as there is so much information, I would prefer if the actual page, as is, was sent to me by email as a html page with fields completed. I understand that I would need to remove the "fields" and I think replace with $fieldnames.

Thus, once received, it can be printed as was on the screen.

Does this make sense?

It is so that I can use tables to spread the data out in the email.

The code I use at the moment to send the email is:


sub makemail2 {
print MAIL<<_E_O_M_;
To: $support
From: $senderemail
Subject: $subject

Hey $support,

First Name: $companyname
Last Name: $sendername
Email Address: $senderemail
Telephone: $sendertele
AND TEHRE ARE LOADS MORE WHERE THE ABOVE CAME FROM !!!
Comments: $comments

_E_O_M_
}


I have tried to change it to the following but it doesn't seem to work:


sub makemail2 {
print MAIL<<_E_O_M_;
To: $support
From: $senderemail
Subject: $subject
<html>
<head></head>
<body>
<table cellspacing=0 cellpadding=0 width="100%" border=0>
<tbody>
<td valign=top rowspan=2 class="app_body">
<font face=Arial,Helvetica size=5>
<strong>1&nbsp;&nbsp;</strong></font></td>
<td class="app_body">Name</td>
<td> $fname</td>
</tr>
<tr>
<td class="app_body">Address (1st line)</td>
<td> $address</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Address (2nd line)</td>
<td> $address2</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Address (3rd line)</td>
<td> $address3</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Postal town</td>
<td> $town</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Postcode</td>
<td> $postcode</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Telephone</td>
<td> $telephone</td>
</tr>
<tr>
<td class="app_body">&nbsp;</td>
<td class="app_body">Email Address&nbsp;</td>
<td> $email</td>
</tr>
</tbody>
</table>
</body>
</html>


Could anyone help me please? (I know I have to rid it of the class= too!)

Calilo
01-20-2003, 01:48 AM
I dont know much about html mails, but i think you have to specify at the mime/type, or its mailing similar, that this will be an html fomated mail, otherwise it wont work, abut i also dont see whats not working properly

Calilo

ivy
01-20-2003, 12:00 PM
i think you have to specify at the mime/type, or its mailing similar

But where?!!!!!

At the moment, I am considering saving a log as a text delin. file, importing into Excel and Mailmerging in a pre-formatted Word document. Seems a lot of hassle though!

Calilo
01-21-2003, 01:42 AM
This is how you set the mime type, im not sure whats the right type for html mails, that is easier to find, just remember print SENDMAIL changes to what ever name you have for it or which ever way you are using to send the mail



print SENDMAIL "Content-type: text/plain\n\n";

Calilo

crackn101
02-01-2003, 05:12 AM
Hi.

Calilo is right.
But use html instead of plain.
print SENDMAIL "Content-type: text/html\n\n";

Print this line after all of your headers ( To, From, Subject etc. )
but Before the body of your email.

I wrote a simple script for a friend of mine that does
just that.
It uses the original html form as a template.
It loads the form, fills in the data submited, then
emails the form, all filled in, exactly as it looked from the
website.

Code is a little retarded, but it works.
Also too, we had to put a copy of the html form into the
cgi-bin with the script. ( To load as a template )
For some reason it wouldn't let us specify the one in our www folder. Probably just a permission setting.

Hope it helps.

Crackn101

hogtied
02-26-2003, 11:03 PM
Hello,

I have this perl script so far:

#!/usr/local/bin/perl

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

$formData = $ENV{'QUERY_STRING'};
@data = split(/&/, $formData);
foreach $data (@data) {
($name, $value) = split(/=/, $data);
$email{$name} = $value;
}

open(MAIL, "|/usr/bin/sendmail -t");
print MAIL "To: $email{to}\n";
print MAIL "From: $email{from}\n";
print MAIL "Subject: Feedback from\n\n";
close (MAIL);

this alone works fine. What I want to do is to be able to send pictures. The only way I know (and correct me if I'm wrong) is that this can only be done using HTML not Plain Text.

My question is how do you send an HTML email with pictures in it.??

Thanks,
Hogtied

crackn101
02-27-2003, 12:25 AM
. . . ( Your usual perl code here ) . . .

open(MAIL, "|/usr/bin/sendmail -t");
print MAIL "To: $email{to}\n";
print MAIL "From: $email{from}\n";
print MAIL "Subject: Feedback from\n\n";
print MAIL "content-type: text/html\n\n";
print MAIL "<html><body>";
print MAIL "<center>";
print MAIL " HERE is some of your email message\n";
print MAIL '<img src="http://www.yoursite.com" width="200" height="200" border="0"> ';
print MAIL "HERE is the rest of your email message\n";
print MAIL "</center>";
print MAIL "</body></html>";
close (MAIL);

. . . ( The rest of your perl code here ) . . .

Format the body of your email into an html page.
Including the html image tag.
Make sure that the url to your image is working.
when the recipient opens your email, it goes out and
retireves the image at that time.
Only way i know how to display an image in an email using perl,
is using html like you said.

Crackn101

hogtied
02-27-2003, 01:06 AM
sorry about last post. I was trying to start a new one..

:)

ivy
02-28-2003, 01:21 AM
Hi crackn101

I am sorry that I have not replied sooner - I dod not get an email telling me that a repsonse was here...... I got one for the post just bepfre this though - perhaps I overlooked an email.

Anyway, I have just downloaded yuor zip file and will look at it tomorrow as it is now 1.20am and I'm about to crash for the evening.

Thank you very much for your response........

I'll let you know how it goes. Watch the space below!