PERL: sending an array via e-mail

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
Still a perl newbie here...I've been editing others' scripts for a few months now. Maybe its time to really sit and learn it?


I have a script that collects data from an html form as an array. It has been usually sending this info to a tab delimited text file like this:

$t = "\t";
$whyvisit = &import_textbox($SURVEY::whyvisit);

$survey = $today_date.$t.
$today_time.$t.
"{name}".$t.
"{organization}".$t.
"{homepage}".$t.
"{email}".$t.
"{profession}".$t.
$whyvisit.$t.

The final lines of this SURVEY package are:

@lines = &fill_template("type" => "STRING",
"source" => "survey",
"package" => "SURVEY");
print OUTF @lines;
close (OUTF);

Question - how can I print this to an e-mail instead of the text file? Just for testing, I've added the following code (from formail.pl) which doesn't even have any data from @lines, but I still get the typical HTTP 500 "Page cannot be displayed" in IE5 after a significant pause. Unfortunately, I don't have access to the log right now.

open(MAIL,"|/usr/lib/sendmail -i -t");
print MAIL "To: emailhere@email.com\n";
print MAIL "From: emailhere@email.com\n";
close MAIL;

Thanks in advance...
 

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
DUH - espcape the @ symbol...

My mail lines now read the following, but I get the error 'emailhere/.com' ... User unknown

open(MAIL,"|/usr/lib/sendmail -i -t");
print MAIL "To: 'emailhere/@here.com'\n";
print MAIL "From: 'emailhere/@here.com'\n";
close MAIL;

Note that in the script I really used a REAL e-mail address...I'm using emailhere@here.com for anonymouse sake.
 

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
That did it thanks!

So now I have the data coming straight to mr. e-mail with the command 'print MAIL @lines;' but I'm getting spaces in between the lines rather than tabs. Any way to keep the tabs?

Love this forum...
 

jamesave

Golden Member
Aug 27, 2000
1,610
0
76
What happen if you just output it to a file instead of email? Does it show that tab?

 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
hmmm...
if you view the email in HTML format, multiple spaces (including tabs) are combined into one space (although you can still see the multiple spaces if you view source them)
are you viewing the email in plain text or html?
 

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
yeah - DUH - figured out last night that my mail prog was setup to read as html format rather than raw text.

All is good - thanks everyone! Everytime I have one of these little projects I learn more and more...

Originally posted by: stndn
hmmm...
if you view the email in HTML format, multiple spaces (including tabs) are combined into one space (although you can still see the multiple spaces if you view source them). are you viewing the email in plain text or html?

 

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
AH one more question, not as important since I don't care either way...


Say in the e-mail I wanted to grab the {name} and {email} items from the form, and use them as "From: name, email" in the e-mail sent out. How exactly would I do this given the code in my top-most post? Here's my current print MAIL:

open(MAIL,"|/usr/lib/sendmail -i -t");
print MAIL "To: emailhere\@where.com\n";
print MAIL "Subject: Feedback\n\n";
print MAIL @lines;
close MAIL;

Thanks again!
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
i think it's:
print MAIL "From: $name <$email>"
is that what you were looking for?
 

MIDIman

Diamond Member
Jan 14, 2000
3,594
0
0
Originally posted by: stndn
i think it's:
print MAIL "From: $name <$email>"
is that what you were looking for?

That's what I want to do, but it doesn't work - instead I get something generic like "X-Domain Web Services <www@www.x-domain.com>" in the From box. I think it has to do with the way the form's info is collected...i.e. look at the way the information is collected into @lines in my first post. Is there any way to grab the information from there? I don't really know anything about packages.