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

sending email w/ carriage returns, from textarea through query string

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
hello.

i've been at this all night, and i can't get it right.

i'm using AJAX, and i'm taking information from a form on an html page, a textarea to be specific.

the information in the TA gets formatted into a query string, then passed to a script which i parse and put the value in the subject area of the sendmail.

problem is, i can't seem to pass carriage returns.

here's my code:

Code:
script.pl?a=test%20subject&b=here%20we%20have%5Cna%20sentence%20or%20two%5Cn%5Cnsincerely,%5Cnadministrator

$esub=param('a');
$emsg=param('b');

open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
select (MAIL);
print << "EOF";
To: Joe Blow <jb\@joeblow.com>
From: Administrator <admin\@mysite.com>
Subject: $esub
$emsg
EOF

close (MAIL);
select (STDOUT);

if i were to put the string "here we have\na sentence or two.\n\nsincerely,\nadministrator" it comes out in the email fine. but trying to pass the same sentence, complete with new lines from a variable, it prints the new lines literally.

i've tried unescaping the parameter:

$emsg = uri_unescape($emsg);

but that doesn't work either.

any ideas?

- g
 
That's because you're passing %5Cn to the script, which is a literal backslash followed by an 'n' character. You want to URL-encode the newline character, which IIRC is %0a, though you'll want to check that.
 
Before you make the AJAX call to the script , i'm assuming by JavaScript, as ishnid says, you need to encode the URL...

Code:
var lender = escape(document.getElementById('lender').value);[/quote] so I create JS vars which hold the escaped data and then do the ajax call with the vars.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top