Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
PHP mail() problem
Old
  (#1)
Delta Storm
Guest
 
Posts: n/a
Default PHP mail() problem - 05-14-2007, 03:55 AM

Hi,

I'm having problem with character encoding in PHP mail functions.

CODE:
$headers.= "Content-Type: text/html; charset=iso-8859-1";
$headers .= "MIME-Version: 1.0 ";
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .="Content-Type: multipart/alternative;
boundary=0-92766976-1174383938=:29106";
$to = "EMAIL REMOVED";
$subject = $_POST['cat'];
$body = $_POST['text'];
if (mail($to, $subject, $body, $headers))
{
echo('<p>Message successfully sent!</p><br /><a
href="showarticle.php?cid=5&id=3">Povratak</a>');
}
else
{
echo('<p>Message delivery failed...</p><br /><a
href="showarticle.php?cid=5&id=3">Povratak</a>');
}

Im receiving mail as you see using yahoo.com. It all works except it
doesn't show croatian letters... I also tried with encoding utf-8, same
thing...
ÄŒÄ*ŽÅ*Đ

Please help, thank you very much!
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] PHP mail() problem
Old
  (#2)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] PHP mail() problem - 05-14-2007, 03:55 AM

2007. 03. 20, kedd keltezéssel 10.54-kor Delta Storm ezt Ã*rta:
> Hi,
>
> I'm having problem with character encoding in PHP mail functions.
>
> CODE:
> $headers.= "Content-Type: text/html; charset=iso-8859-1";
> $headers .= "MIME-Version: 1.0 ";
> $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
> $headers .="Content-Type: multipart/alternative;
> boundary=0-92766976-1174383938=:29106";
> $to = "EMAIL REMOVED";
> $subject = $_POST['cat'];
> $body = $_POST['text'];


you should check those values first before putting them into mail().
they can contain spammer tricks like putting newlines in the subject and
then cc header lines or something similar....

> if (mail($to, $subject, $body, $headers))
> {
> echo('<p>Message successfully sent!</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
> else
> {
> echo('<p>Message delivery failed...</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
>
> Im receiving mail as you see using yahoo.com. It all works except it
> doesn't show croatian letters... I also tried with encoding utf-8, same
> thing...
> ÄŒÄ*ŽÅ*Đ


what is the charset of the webpage displaying the form which triggers
this function? it must be set to the same value as the email otherwise
your email sending function won't receive the croatian letters at all,
so it cannot send them too...

hope that helps
Zoltán Németh

>
> Please help, thank you very much!
>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] PHP mail() problem
Old
  (#3)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] PHP mail() problem - 05-14-2007, 03:55 AM

Hi.

Recently I have this kind of issue.
This is a possible solution:

$text="message text";
$subject="message subject";
$header="From: EMAIL REMOVED\r\n".
"MIME-Version: 1.0\r\n".
"Content-type: text/html; charset=utf-8\r\n".
"Content-Transfer-Encoding: 8bit\r\n";


$subject2=utf8_encode($subject);
$text2=utf8_encode($text);
mail("EMAIL REMOVED",$subject,$text2,$heade r);

This encodes message to UTF-8 and should work.

2007. március 20. 10.54 dátummal Delta Storm ezt Ã*rta:
> Hi,
>
> I'm having problem with character encoding in PHP mail functions.
>
> CODE:
> $headers.= "Content-Type: text/html; charset=iso-8859-1";
> $headers .= "MIME-Version: 1.0 ";
> $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
> $headers .="Content-Type: multipart/alternative;
> boundary=0-92766976-1174383938=:29106";
> $to = "EMAIL REMOVED";
> $subject = $_POST['cat'];
> $body = $_POST['text'];
> if (mail($to, $subject, $body, $headers))
> {
> echo('<p>Message successfully sent!</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
> else
> {
> echo('<p>Message delivery failed...</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
>
> Im receiving mail as you see using yahoo.com. It all works except it
> doesn't show croatian letters... I also tried with encoding utf-8, same
> thing...
> ÄŒÄ*ŽÅ*Đ
>
> Please help, thank you very much!

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] PHP mail() problem
Old
  (#4)
Richard Lynch
Guest
 
Posts: n/a
Default Re: [PHP] PHP mail() problem - 05-14-2007, 03:55 AM

On Tue, March 20, 2007 4:54 am, Delta Storm wrote:

Disclosure:
What I understand of Unicode could fit in a matchbook...

> I'm having problem with character encoding in PHP mail functions.
>
> CODE:
> $headers.= "Content-Type: text/html; charset=iso-8859-1";
> $headers .= "MIME-Version: 1.0 ";
> $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;


WILD GUESS ALERT!!!
You're trying to p*** 16-bit characters in an 8bit transfer encoding,
whatever the heck that is...

Seems to me you need a bigger "bucket"...

You do realize that sending HTML Enhanced (cough, cough) email is
quite likely to get it marked as spam and never seen by the intended
recipient, right?...

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: PHP mail() problem
Old
  (#5)
Manuel Lemos
Guest
 
Posts: n/a
Default Re: PHP mail() problem - 05-14-2007, 03:56 AM

Hello,

on 03/20/2007 06:54 AM Delta Storm said the following:
> Hi,
>
> I'm having problem with character encoding in PHP mail functions.
>
> CODE:
> $headers.= "Content-Type: text/html; charset=iso-8859-1";
> $headers .= "MIME-Version: 1.0 ";
> $headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
> $headers .="Content-Type: multipart/alternative;
> boundary=0-92766976-1174383938=:29106";
> $to = "EMAIL REMOVED";
> $subject = $_POST['cat'];
> $body = $_POST['text'];
> if (mail($to, $subject, $body, $headers))
> {
> echo('<p>Message successfully sent!</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
> else
> {
> echo('<p>Message delivery failed...</p><br /><a
> href="showarticle.php?cid=5&id=3">Povratak</a>');
> }
>
> Im receiving mail as you see using yahoo.com. It all works except it
> doesn't show croatian letters... I also tried with encoding utf-8, same
> thing...
> ÄŒÄ*ŽÅ*Đ


Several things are wrong.

I think Croatian letters need ISO-8859-2 character set. utf-8 is fine
too. Make sure you use the same encoding as you use for the HTML page
where your form is.

Other than that, you should not use 8bit content transfer encoding when
you have non-ASCII characters in the text.

You should use quoted-printable encoding for the body and q-encoding for
the headers.

You have multiple Content-Type headers. Only one is right. For messages
with HTML, you should use only multipart/alternative. However the body
must enclose both a text/plain and a text/html alternative parts.

This is all a bit complicated to do with a small script like you have.
It is much simpler to use ready to use components to do the hard work of
message ***embly for you.

I use this MIME message cl***. It can handle all you need including
non-ASCII character encoding. Take a look at the
test_simple_html_mail_message.php example script.

http://www.phpcl***es.org/mimemessage


--

Regards,
Manuel Lemos

Metastorage - Data object relational mapping layer generator
http://www.metastorage.net/

PHP Cl***es - Free ready to use OOP components written in PHP
http://www.phpcl***es.org/
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top