RE: save email in original layout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 

-----Original Message-----
From: Richard Lynch [mailto:ceo@xxxxxxxxx] 
Sent: Friday, February 23, 2007 2:19 PM
To: Richard Kurth
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  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>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux