Forum Moderators: open

Message Too Old, No Replies

Paste html into email body - all I see is source code

Why is the page not rendered by the email client?

         

specter

12:32 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

I'm trying to send a web page via mail by copying/pasting its html code in the mail body, but in receiving it I have only a source-view page: the code itself is shown instead of the properly formatted web page...

Why this? can I get proper html page view?

Habtom

12:35 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is all I think because of the following header missing, or improperly set:

$headers .= "Content-type: text/html\r\n";

Check that and post back.

Habtom

specter

12:47 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing happens...

Any code I type in the mail body is shown exactly as it is: if I type in [ b]blabla[/b ] i see exactly [b ]blabla[/b ] (here I distanced the brackets in order to show you what I see, but in the mails the coding is correct)...

Habtom

12:50 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Can you post your header info here? May be I will find out something.

Habtom

specter

1:13 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well,

here is the whole code:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>test</title>
</head>

<body link="#000000" vlink="#FF0000" alink="#000000">

<p align="center"><font face="Eurostile" size="7">Test page</font></p>
<div align="center">
<center>
<table width="918" border="0">
<tbody>
<tr>
<td align="middle" width="1075" colSpan="3">
<p align="center"><font face="Eurostile" size="5">testing page bla bla&nbsp;</font></p>
</td>
</tr>
</tbody>
</table>
</center>
</div>
<div align="center">
<center>
<table width="80%" border="0">
<tbody>
<tr>
<td width="100%">&nbsp;
<hr width="800">
<p class="fd_results"><font face="Verdana" size="2"><b>test alpha</b></font></p>
<p class="fd_results"><font face="Verdana" size="2">test beta</font></p>
<p class="fd_results">&nbsp;</p>
<p class="fd_results">&nbsp;
</p>
</center>
<p class="fd_results" align="right">
<b><a href="http://"><br>
</a></b>
<font size="2" face="Verdana">Back
to the index</font>
</p>
<center>
<hr width="800">
<p>&nbsp;</p>
</center>
<table width="60%" border="0">
<tbody>
<tr>
<td width="100%">
<p align="left"><font face="arial,helvetica" color="#000000" size="2"><a style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
blabla</a><a style="COLOR: #000000">.net</a></font></p>
</tr>
</tbody>
</table>
</tr>
</tbody>
</table>
</div>

</body>

</html>

Obviously, it is correctly formatted if I view it trough any web browser...

Thanks for any useful hint.

[edited by: tedster at 6:59 pm (utc) on June 10, 2007]
[edit reason] add breaks to prevent side-scrolling [/edit]

Habtom

1:18 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not the HTML page, I meant the PHP, where you set your headers, and where you have the mail function.

Habtom

specter

1:29 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But I have that problem with any html code I copy/paste in a mail body, even if not script-generated: Just to esthabilish if was a script or a viewing problem, I created a sample page with front page (the one I posted), than simply I copied/pasted it in the mail body and sent it to myself...
the result is still a source view page...

So that's not a script issue,I guess...

Habtom

1:32 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> than simply I copied/pasted it in the mail body and sent it to myself

You mean like Gmail, Yahoo? I don't think they are meant to send HTML emails, or are they?

But the problem, almost certainly is with the headers. Most email problems of this kind arise from wrongly set headers.

Habtom

specter

1:44 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here is the code of the mailing subroutine (perl):

# prints report

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

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

print "<p><font face=Arial Black size=4><b>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...

rocknbil

4:22 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Someone edit those &nbsp;'s to get this thread back on the planet. :-D

specter if youre using perl, I answered your problem in the perl forum, [webmasterworld.com] but here it is again for your convenience.

The code you posted above prints to the browser. To print to mail you open a mail filehandle, then print the output to that filehandle. print "hello world" prints to STDOUT, which is whatever process calls it (the browser.)

You should find something like this in your script. The problem is the content-type headers need to print to the mail filehandle - NOT STDOUT - see bolded text below. In the below sample, ¦ is the unbroken pipe.

## Open the mail program and choose a filehandle.
## in this case, MAIL. If it's sendmail, use -t
## to extract the address from mail text and avoid
## pipe injection. The common install for sendmail
## is $your_mail_program = '/usr/sbin/sendmail';

open (MAIL,"¦ $your_mail_program -t") or die("cannot open mail program");

## Now print headers to the MAIL filehandle

print MAIL "To: $to_email\r\n";
print MAIL "From: $from\r\n";
print MAIL "Subject: $subject\r\n";
print MAIL "MIME-Version: 1.0\r\n";
print MAIL "Content-Type: text/html; charset=US-ASCII\r\n";

## Print message
print MAIL "$body";
## Close filehandle, flushing buffer or the message will be blank

close (MAIL);

Also note after the last header, use only one \r\n. Unlike printing to the browser, using two can munge up the header and case it to print as plain text in some email clients.

rocknbil

4:32 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



P.S.:

But I have that problem with any html code I copy/paste in a mail body, even if not script-generated

This is a different issue and has to do with the settings in the mail client. The client is converting your html carats to entities or ASCII equivalents, so they will display as you've pasted it. You can probably set the mail client to parse HTML in the body of the mail.

A better alternative in this case *might* be to send an html page as an attachment, then set the client (temporarily) to include text or html attachments in the body of the email.

specter

8:45 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok!
Now I'm closer to the solution.
The script is not conceived to print email output, but browser output!

Really,I receive the report via e-mail because the script is cron-executed daily, and the cron output is sent to the mail address I specified in the control panel.
So, the report subroutine is not proper for mail files.
Now, I need to know how to edit properly that script so that it will send autonomously proper email formatted file to my mailbox.

I wait your kind replies in the perl thread.Thanks.

tedster

9:49 pm on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Discussion continues here:

[webmasterworld.com...]