|
Posted by amygdala on 08/19/07 14:16
Hi all,
Another problem that has been bugging me for a while now, but which I swept
under the rug too long too now is a mail encoding problem at my (shared)
webhost.
The problem is that on different occassions when I send the exact same mail
(same e-mail address, same name, same body content) through my site's
contactform it produces the wellknown strange characters instead of the
intended diacritical characters. This problem also shows up at the
contactform for a client of mine, which site is hosted on the same webhost.
I've contacted my webhost a few times already, but they don't know what
could be the cause of the problem either.
This is the setup I'm using on my webhost:
The host runs fast-cgi PHP5 with customizable php.ini files per
domain/website on Slackware Linux.
All my php files are saved as 1252 ANSI. All my HTML output have
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
meta tags. The difference in these two encodings shouldn't be a problem is
my guess. But perhaps I'm wrong?
And my Mailer class uses the following code to send mail:
public function send()
{
if( is_null( $this->getErrors() ) )
{
$cc = implode( ', ', $this->cc );
$bcc = implode( ', ', $this->bcc );
$to = implode( ', ', $this->to );
$headers = 'From: ' . $this->from . LF;
if ( !empty( $cc ) ) $headers .= 'Cc: ' . $cc . LF;
if ( !empty( $bcc ) ) $headers .= 'Bcc: ' . $bcc . LF;
$headers .= 'MIME-Version: 1.0' . LF;
$headers .= 'X-Mailer: ' . $this->mailerName . LF;
$headers .= 'Content-Type: text/plain; charset=iso-8859-1' . LF;
$headers .= 'Content-Transfer-Encoding: 8bit' . LF;
$subject = $this->subject;
$body = $this->body;
if( mail( $to, $subject, $body, $headers ) )
{
return true;
}
$this->setError( 'general', 'error', basename( __FILE__, '.php' ),
__LINE__ );
return false;
}
else
{
return false;
}
}
Sometimes, when I run in to the problem I change the following lines in my
send() function to utf8 encoding
$headers .= 'Content-Type: text/plain; charset=utf-8' . LF;
$body = utf8_encode( $this->body );
Then, it seems to work for a while. But then all of a sudden it shows the
same problem again. Eventhough I send the same test mail.
The body content I send is:
test λθο
Which shows up as:
test ëèï
Does anybody have any idea what might be causing this weird problem?
Thanks
Navigation:
[Reply to this message]
|