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

dynamic page in e-mail

Status
Not open for further replies.

Perlwannabe

Technical User
Mar 7, 2006
57
IT
Hello,

I have a perl .cgi script that generates a report and sends it via e-mail,but when I open the mail I have that page only in source-view, instead of the properly html format;

What can be the problem?

Here is the report code:

Code:
Content-type: text/html

<html><body>
<p><font face=Arial Black size=4><b>blabla</b></font></p>
<p><font face=Verdana><b>Your report</b></font></p>
<p><b><font face=Verdana size=2>Today the following tasks have been executed successfully:</font></b></p>
<p><font face=Verdana size=2>bla</font></p>
<p><font face=Verdana size=2>blabla</font></p>
<p><font face=Verdana size=2>blablabla</font></p>

I thought that ending body and html tags are missing but I tried up copying/pasting that code on a new Front Page file and it looks correctly...

please give me a suggestion.Thanks.
 
Where is your code sending the email?

And are you viewing the email in a client that supports html Content-type?

- Miller
 
The problem is on the client:
If I copy/paste any html code in a mail and send it to myself, it shows me source-view page...
 
Check your outlook express settings.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
already done.
It seems all right...

firewall issue?
 
Without seeing the code which creates the email I'm stabbing in the dark but it looks like you might be specifying the 'Content-type' outside of the email filehandle. The code below always works for me. Make sure you've coded similar.

open (MAIL_FILE, "|path_to_sendmail -t);
print MAIL_FILE "To: recipient\n";
print MAIL_FILE "From: sender\n";
print MAIL_FILE "Subject: Whatever ...\n";
print MAIL_FILE "Content-type: text/html; charset=iso-8859-1\n\n";
print MAIL_FILE "<head></head>\n";
print MAIL_FILE "<html><body>\n";
print MAIL_FILE "<p>Contents of the report ...</p>\n";
print MAIL_FILE "</body></html>";
close (MAIL_FILE);
 
Well, the client shows me source-view code pages with any html code, as I verified...
So the problem could not be the mail code generated from the script, but, again, it regards the mail client...

The settings are ok.so I'm not able to understand what's going wrong...
 
There are only two possible causes for this. One, the email that is being generated is not formatted properly. Two, the client does not know how or is not configured for html Content-type.

Copying and pasting html code and sending it to yourself does not prove anything. Instead use a third party email source like gmail in which you know for certain that the email is of Content-type=html.

If the client reads this email as html, then you have a problem with how your original email is being generated. Either read up on how to properly format an email for html, or show us your code so that we can help you debug it.

However, if the client is confirmed as the problem, then why are you asking here? This is a perl forum, not an outlook express forum. Read the docs or call up your trusty geek to come fix your computer.

- Miller
 
However, if the client is confirmed as the problem, then why are you asking here?

Because is not confirmed,as yourself claimed, if copying/pasting any code doesn't prove anything...

Anyway I'll try and I'll let you know.

Thanks
 
I done some tests and I esthabilished that is not a client issue.
So, it's a sort of problem with the script;

Here is the mailing sub code:

Code:
#      prints report

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

print "<html><body>\n";

print "<p><font face=Arial Black size=4><b>mail test</b></font></p>\n";
print "<p><font face=Verdana><b>Your report</b></font></p>\n";
print "<p><b><font face=Verdana size=2>Today the following tests have been executed successfully:</font></b></p>\n";
foreach(@completed){
	print "<p><font face=Verdana size=2>$_.htm</font></p>\n";
}

Hope it will be helpful.

Thanks.
 
Perlwannebe said:
So, it's a sort of problem with the script;

It either is or it isn't.

And this is not enough code to be able to debug. Show us where you are actually sending the email and creating the headers, otherwise there is nothing we'll be able to do to help.

For an easy solution just use MIME::Lite

- Miller

PS.
I'm unsubscribing from this thread. Next time someone asks to see your code, answer them straight out instead ignoring it like you did in this thread.
 
I apologize.Ignoring your request was accidental...

here is the whole code:

Code:
#!/usr/bin/perl

#       localhost




#	Configuration


#        pswd

$password = 'blah';

	full URL of script.cgi

$admin_url_base = '[URL unfurl="true"]http://www.blahblah.net/script.cgi';[/URL]


# 	minimum number of pages you want to create each day.

$minpages = 1;

#	maximum number of pages you want to create each day.

$maxpages = 6;


#	path to the script (needed for cronning) 
#       because the default probably won't work.

$fullpath = '/home/user/public_html/';


##### Script begins #####

#       modules

use CGI::Carp qw (fatalsToBrowser);
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
$ua = LWP::UserAgent->new;

#      variables

$keywords = 'pages.txt';
$klist = '';
$admin_url = $admin_url_base . '?createpages';

#      open source file to read

open (KEYS, "<$fullpath$pages");
@kd = <KEYS>;
close (KEYS);

#      creates the random algo
srand();
$range = $maxpages - $minpages;
$random_number = int(rand($range)) + $minpages;

#      formats the arrays

for ($a=1;$a<=$random_number;$a++){
	$klist .= shift(@kd);
}
chomp($klist);

@completed = split(/\n/,$klist);


#      opens source file to overwrite current status

open (KEYS, ">$fullpath$pages");
print KEYS @kd;
close (KEYS);

#      uploads pages in the form

$req = (POST $admin_url,
    [ 
		'pass' => $password,
		'checkdata' => '1',
		'pagenames' => $klist
    ]);

$response = $ua->request($req);

[b]#      prints report

print "Content-type: text/html; charset=iso-8859-1\n\n";

print "<html><body>\n";

print "<p><font face=Arial Black size=4><b>mail test</b></font></p>\n";
print "<p><font face=Verdana><b>Your report</b></font></p>\n";
print "<p><b><font face=Verdana size=2>Today the following new pages have been created successfully:</font></b></p>\n";
foreach(@completed){
	print "<p><font face=Verdana size=2>$_.htm</font></p>\n";
print "</body></html>\n";
}[/b]
exit;


this is intended as a helper script:it takes a random number of titles from the pages.txt file and post them in the form of another script control panel that generates automatically new web pages, then generates a report of the job.
It's cronned for a daily execution and the mail I receive is the cron output, so probably the script is not intended to send directly mails autonomously, but more than likely, a browser output.This explain why the code looks fine in my browser, while is not workingin the mails.

Probably I need to edit it in order to get him generating proper mail files, but i don't know how to proceed...

Thanks for the help.
 
It's cronned for a daily execution and the mail I receive is the cron output

Thats the problem. Use the MIME::Lite module to send the email and your problem should get resolved. Or maybe someone knows a a way to send html formatted email via cron.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Did you see the code above?

The script generatyes browser output not a mail file.
So I don't think adding mime module would fix the problem,or am I wrong?

In the case,anyway,where should I add that module in the script??
 
Did you see the code above?

I still have vision in one eye and I read what you posted.

The script generatyes browser output not a mail file.

If you say so. Actually it generates text that has some html tags in it.

So I don't think adding mime module would fix the problem,or am I wrong?

Yes, you are wrong.


In the case,anyway,where should I add that module in the script??

Read the documentation. Miller posted the link. It is very easy to understand. The only catch might be that the module is not installed

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Is it me.. or is this the most interesting thread ever!!!!

Someone has to document this as a FAQ "How to insult those who's help you need most" :)

 
He's just confused. He needs to tell cron to not send an email and use MIME::Lite or other method to send an email with the appropriate headers for an html encoded message.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top