save email in original layout

This is a discussion on save email in original layout within the PHP General forums, part of the PHP Programming Forums category; I need to save an email in a mysql database so that it retains it's original layout so the ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-21-2007
Richard Kurth
 
Posts: n/a
Default save email in original layout

I need to save an email in a mysql database so that it retains it's
original layout
so the example below

Hello ,

Do you dream of a better life? Do you wish you had financial stability
and freedom? Would you like to be your own boss?

would look like this when the file is saved

\r\n Hello ,\r\n\r\n\r\n Do you dream of a better life? Do you wish you
had financial stability and freedom? Would you like to be your own boss?

how do I insert all the line spaces like above

Reply With Quote
  #2 (permalink)  
Old 02-21-2007
David Robley
 
Posts: n/a
Default Re: save email in original layout

Richard Kurth wrote:

> I need to save an email in a mysql database so that it retains it's
> original layout
> so the example below
>
> Hello ,
>
> Do you dream of a better life? Do you wish you had financial stability
> and freedom? Would you like to be your own boss?
>
> would look like this when the file is saved
>
> \r\n Hello ,\r\n\r\n\r\n Do you dream of a better life? Do you wish you
> had financial stability and freedom? Would you like to be your own boss?
>
> how do I insert all the line spaces like above


If you insert a string with EOL characters into mysql, the EOL characters
are added as you might expect.

However, I suspect your question might really be:

How do I display this email in a web page with the original format? And two
potential answers are via php's nl2br() or HTML's <PRE> tags.

Ooh look, clever sigmonster :-)

Cheers
--
David Robley

It's as easy as 3.14159265358979323846264338327950...
Today is Boomtime, the 52nd day of Chaos in the YOLD 3173.
Reply With Quote
  #3 (permalink)  
Old 02-23-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] save email in original layout

http://php.net/mysql_real_escape_string is the only thing you need to
worry about as far as MySQL is concerned.

Translating from Email newlines to HTML newlines to OS newlines is
another kettle of fish...

Email newlines are SUPPOSED to be \n, except that some ancient Windows
MTAs insisted on using \r\n and...

So I'm concerned to see the \r in the emails, as they shouldn't be
there...

And, of course, if you display this to a browser, you would need
something like:
echo nl2br(htmlentities($email));
to give the appearance of line-breaks in HTML.

To send it back out as email, with a real MTA, you'll probably need to
replace the \r\n with \n, though the real MTA might even be smart
enough to do that, knowing that it came from a broken MTA in the first
place.

Did I just confuse email headers (\n only) with the body (\r\n) again?
I do that all the time... Experimentation or reading RFCs will
straighten you out on this one, though you're always at the mercy of
the MTAs involved, which may or may not be doing it right...

You also might as well prepare now for the Outlook users who will
insist on using ASCII control characters for things like quote marks
because they want those curly quotes that DO NOT WORK for anybody
other than MS users... There's several solutions at http://str_replace
for that one.

On Wed, February 21, 2007 12:11 am, Richard Kurth wrote:
> I need to save an email in a mysql database so that it retains it's
> original layout
> so the example below
>
> Hello ,
>
> Do you dream of a better life? Do you wish you had financial
> stability
> and freedom? Would you like to be your own boss?
>
> would look like this when the file is saved
>
> \r\n Hello ,\r\n\r\n\r\n Do you dream of a better life? Do you wish
> you
> had financial stability and freedom? Would you like to be your own
> boss?
>
> how do I insert all the line spaces like above
>



--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Reply With Quote
  #4 (permalink)  
Old 02-24-2007
Richard Kurth
 
Posts: n/a
Default RE: [PHP] save email in original layout



-----Original Message-----
From: Richard Lynch [mailto:ceo@l-i-e.com]
Sent: Friday, February 23, 2007 2:19 PM
To: Richard Kurth
Cc: php-general@lists.php.net
Subject: Re: [php] save email in original layout

http://php.net/mysql_real_escape_string is the only thing you need to worry
about as far as MySQL is concerned.

Translating from Email newlines to HTML newlines to OS newlines is another
kettle of fish...

Email newlines are SUPPOSED to be \n, except that some ancient Windows MTAs
insisted on using \r\n and...

So I'm concerned to see the \r in the emails, as they shouldn't be there...

And, of course, if you display this to a browser, you would need something
like:
echo nl2br(htmlentities($email));
to give the appearance of line-breaks in HTML.

To send it back out as email, with a real MTA, you'll probably need to
replace the \r\n with \n, though the real MTA might even be smart enough to
do that, knowing that it came from a broken MTA in the first place.

Did I just confuse email headers (\n only) with the body (\r\n) again?
I do that all the time... Experimentation or reading RFCs will straighten
you out on this one, though you're always at the mercy of the MTAs involved,
which may or may not be doing it right...

You also might as well prepare now for the Outlook users who will insist on
using ASCII control characters for things like quote marks because they want
those curly quotes that DO NOT WORK for anybody other than MS users...
There's several solutions at http://str_replace for that one.

On Wed, February 21, 2007 12:11 am, Richard Kurth wrote:
> I need to save an email in a mysql database so that it retains it's
> original layout so the example below
>
> Hello ,
>
> Do you dream of a better life? Do you wish you had financial
> stability and freedom? Would you like to be your own boss?
>
> would look like this when the file is saved
>
> \r\n Hello ,\r\n\r\n\r\n Do you dream of a better life? Do you wish
> you had financial stability and freedom? Would you like to be your
> own boss?
>
> how do I insert all the line spaces like above
>


My problem is I have a JavaScript that will hold all the email templates on
the page that is displayed and when you select one it puts it in the
<textarea> so you can edit it and then send it out. When it appears in the
<textarea> it does not have all the /r/n in there anymore. The JavaScript
errors out if I just put <br> or spaces in it. That is the only reason I
need the /r/n in the file. Below is what the script looks like. The first
script works the second does not work. The only difference is the spaces I
put in the first email in the second example. I generate the last part of
this script from the database where the email templates are stored


THIS ONE WORKS
<form method="post" name="scriptform" action=sendfollowup.php>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

function changescript() {
var t1="this is a test subject line";
var s1="This is a test message. This is a test message This is a test
message This is a test message This is a test message This is a test message
This is a test message This is a test message This is a test message This is
a test message This is a test message This is a test message This is a test
message This is a test message This is a test message This is a test message
This is a test message";
var t2="this is a test subject line";
var s2="\r\n This ,\r\n\r\n\r\n s a test message This is a test message? s
a test message This is a test message? s a test message This is a test
message? \r\ns a test message This is a test message";
switch(document.scriptform.scriptn.value)
{case '1' : MM_setTextOfTextfield('thescript','',s1);
MM_setTextOfTextfield('subject','',t1); break;
case '2' : MM_setTextOfTextfield('thescript','',s2);
MM_setTextOfTextfield('subject','',t2); break;
default : break; }
}
//-->
</script>
<p>
Choose Email Follow-up:
<select name="scriptn" onChange="changescript();">
<option value="0" selected>Select...</option>
<OPTION value="1">test1</OPTION>
<OPTION value="2">test2</OPTION>
</select>&nbsp;&nbsp;
<p>
<table cellpadding="5" cellspacing="1">
<tr>
<td>From:</td>
<td>

</td>
</tr>
<tr>
<td>To:</td>
<td>

</td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" size="38" name="subject" value=""></td>
</tr>
<tr>
<td colspan="2">
<table cellpadding="0" cellspacing="0" style="width:100%;">
<tr>
<td nowrap>Message:</td>
<td align=right width:100%;" nowrap>
</td>
</tr>
</table>

<textarea name="thescript" cols="101" rows="15"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<center>
<input type=submit name=sendemail value="Send E-mail">
<input type=button name=close value="Cancel">
</center>
</td>
</tr>
</table>
</form>

THIS ONE DOES NOT WORK
<form method="post" name="scriptform" action=sendfollowup.php>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_setTextOfTextfield(objName,x,newText) { //v3.0
var obj = MM_findObj(objName); if (obj) obj.value = newText;
}

function changescript() {
var t1="this is a test subject line";
var s1="This is a test message.

This is a test message This is a test message This is a test message This
is a test message This is a test message This is a test message This is a
test message This is a test message This is a test message This is a test
message This is a test message This is a test message This is a test message
This is a test message This is a test message This is a test message";
var t2="this is a test subject line";
var s2="\r\n This ,\r\n\r\n\r\n s a test message This is a test message? s
a test message This is a test message? s a test message This is a test
message? \r\ns a test message This is a test message";
switch(document.scriptform.scriptn.value)
{case '1' : MM_setTextOfTextfield('thescript','',s1);
MM_setTextOfTextfield('subject','',t1); break;
case '2' : MM_setTextOfTextfield('thescript','',s2);
MM_setTextOfTextfield('subject','',t2); break;
default : break; }
}
//-->
</script>
<p>
Choose Email Follow-up:
<select name="scriptn" onChange="changescript();">
<option value="0" selected>Select...</option>
<OPTION value="1">test1</OPTION>
<OPTION value="2">test2</OPTION>
</select>&nbsp;&nbsp;
<p>
<table cellpadding="5" cellspacing="1">
<tr>
<td>From:</td>
<td>

</td>
</tr>
<tr>
<td>To:</td>
<td>

</td>
</tr>
<tr>
<td>Subject:</td>
<td><input type="text" size="38" name="subject" value=""></td>
</tr>
<tr>
<td colspan="2">
<table cellpadding="0" cellspacing="0" style="width:100%;">
<tr>
<td nowrap>Message:</td>
<td align=right width:100%;" nowrap>
</td>
</tr>
</table>

<textarea name="thescript" cols="101" rows="15"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<center>
<input type=submit name=sendemail value="Send E-mail">
<input type=button name=close value="Cancel">
</center>
</td>
</tr>
</table>
</form>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:36 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0