strange mail issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

strange mail issue

Post by desperado »

I have the following:

Code: Select all

 
$emailmessage = "
<html>
<head>
<title>Contact Page Request</title>
</head>
<body>";
if (isset($_POST['request1'])) {
$emailmessage .= "<p><font size='2' face='Arial, Helvetica, sans-serif'>Someone requested a quote for the following: </font></p>
  <p><font size='2' face='Arial, Helvetica, sans-serif'>Request: $_POST[quote_client_comment]</p>
  <p><font size='2' face='Arial, Helvetica, sans-serif'>You can generate the quote here: 
<a href='http://****************************************.php?recordID=$quote_id'>CLICK HERE</a></p>
 </body>
</html>
";
 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n";
 
When the email is received and viewed, we see this:
...quote_init.php?recordID#363

while the raw source of the email shows properly:
...quote_init.php?recordID=23363

I'm stumped. I've seen somewhere that # has a hex equivalent of 23, but 8O

any help would be appreciated.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: strange mail issue

Post by requinix »

You've seen things like %23 in a URL, right? It's a way of representing a literal '#' without having any special meaning like a # normally does.
The quoted-printable transfer encoding is the same, except is uses a '=' instead of a '%'. Thus when you put a

Code: Select all

=23
in your quoted-printable message you're really putting in an encoded '#'.

Unless you're actually sending UTF-8 data (doesn't look like you are) use the US-ASCII character set and the 7bit transfer encoding.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: strange mail issue

Post by desperado »

Thanks! I figured it had to do with the headers.

I do use accented characters pulled from a DB, so that's why I use UTF-8.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: strange mail issue

Post by desperado »

Question. Can I use default 7 bit encoding with UTF-8?

Thx
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: strange mail issue

Post by requinix »

No, not really. 7bit means that each character should have the eighth bit as zero, but that doesn't happen with UTF-8. There is an 8bit encoding but it's not handled everywhere: quoted-printable is best.

I think mail() will handle all the dirty work for you, with regards to transfer encoding and the like. Send yourself an email (with only the Content-Type specified in your code) and see what the headers are.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: strange mail issue

Post by desperado »

I removed the transfer encoding and it worked fine.

I thought that if it was not specified, it would default to 7-bit, but you are right, mail() handled it all pretty.

Thanks tasairis.
Post Reply