[PHP] escaping quotes in mail() message

2003-02-03 Thread Lowell Allen
I'm having a problem escaping double quotes in email messages sent with
mail(). The message is built as a string and assigned to a variable and the
variable name is passed to the mail function.

The double quotes appear correctly in a simple test like this:
$message = This message uses 'single' and \double\ quotes.;
mail($sendto, $subject, $message, $headers);

But if $message is built in another part of the script and passed as a
hidden input of a form, the email arrives with the message truncated at the
first double quote encountered. If I do a str_replace() on $message to
escape double quotes, the email shows the escaping backslash but is still
truncated at the double quote!

I've got magic_quotes on, but I think I'm keeping up with stripslashes
because single quotes are showing up correctly.

Can anyone please advise?

--
Lowell Allen


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




Re: [PHP] escaping quotes in mail() message

2003-02-03 Thread 1LT John W. Holmes
 I'm having a problem escaping double quotes in email messages sent with
 mail(). The message is built as a string and assigned to a variable and
the
 variable name is passed to the mail function.

 The double quotes appear correctly in a simple test like this:
 $message = This message uses 'single' and \double\ quotes.;
 mail($sendto, $subject, $message, $headers);

 But if $message is built in another part of the script and passed as a
 hidden input of a form, the email arrives with the message truncated at
the
 first double quote encountered. If I do a str_replace() on $message to
 escape double quotes, the email shows the escaping backslash but is still
 truncated at the double quote!

 I've got magic_quotes on, but I think I'm keeping up with stripslashes
 because single quotes are showing up correctly.

 Can anyone please advise?

You can't escape double quotes in HTML... it doesn't understand.

So, you're ending up with a hidden element like this:

input type=hidden name=whatever value=This message  uses 'single' and
\double\ qutoes.

HTML will cut it off at the first  because it doesn't recognize the escape
character.

The way around this is to use htmlentities() or htmlspecialchars() on your
string before you insert it into the value attribute of your form element.
It will come out decoded on the the other side, so you don't have to worry
about that.

Hope that helps.

---John Holmes...


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




Re: [PHP] escaping quotes in mail() message

2003-02-03 Thread Lowell Allen
 From: 1LT John W. Holmes [EMAIL PROTECTED]
 
 I'm having a problem escaping double quotes in email messages sent with
 mail(). The message is built as a string and assigned to a variable and
 the
 variable name is passed to the mail function.
 
 The double quotes appear correctly in a simple test like this:
 $message = This message uses 'single' and \double\ quotes.;
 mail($sendto, $subject, $message, $headers);
 
 But if $message is built in another part of the script and passed as a
 hidden input of a form, the email arrives with the message truncated at
 the
 first double quote encountered. If I do a str_replace() on $message to
 escape double quotes, the email shows the escaping backslash but is still
 truncated at the double quote!

[snip]

 The way around this is to use htmlentities() or htmlspecialchars() on your
 string before you insert it into the value attribute of your form element.
 It will come out decoded on the the other side, so you don't have to worry
 about that.

John, thanks for the fine reply -- problem solved!

--
Lowell Allen


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