VapiSoft
asked on
php mail for none-English characters.
Hi,
I want to send an email in Hebrew from a PHP server.
I fetch the text from MySQL table.
I set the Text "collation" of the text-column (in the MySQL table) to "hebrew_general_ci".
But when I recive the mail I see gibrish instead of the text.
I want to send an email in Hebrew from a PHP server.
I fetch the text from MySQL table.
I set the Text "collation" of the text-column (in the MySQL table) to "hebrew_general_ci".
But when I recive the mail I see gibrish instead of the text.
Show us your code and maybe we can help.
@mysql_query('set character_set_client="hebr
@mysql_query('set character_set_results="heb
@mysql_query('set collation_connection="hebr
and try php iconv function for text encoding
ASKER
to actionmanager:
I tried the
@mysql_query('set character_set_client="hebr ew"');
@mysql_query('set character_set_results="heb rew"');
@mysql_query('set collation_connection="hebr ew_general _ci"');
and it didn't change anything.
about the iconv, I dont know what parameters to give.
as I wrote, the current text encoding (in the PHP 'collation' is 'hebrew_general_ci");
I tried the
@mysql_query('set character_set_client="hebr
@mysql_query('set character_set_results="heb
@mysql_query('set collation_connection="hebr
and it didn't change anything.
about the iconv, I dont know what parameters to give.
as I wrote, the current text encoding (in the PHP 'collation' is 'hebrew_general_ci");
Did you also set the content encoding in your email form?
ASKER
What do you mean?
I receive mails in Hebrew and I intend to send the mail only to people in Israel (that their client is programmed to receive mail in Hebrew).
I receive mails in Hebrew and I intend to send the mail only to people in Israel (that their client is programmed to receive mail in Hebrew).
If you are using PHP's mail() function. look at this from http://php.net/manual/en/function.mail.php. I think that 'plain' email is US-ASCII character set. You might want to look at the headers in your email client and see what they are using.
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
try with below code
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
and
<?php
$heb = 'put hebrew text here';
$utf = preg_replace("/([\xE0-\xFA ])/e","chr (215).chr( ord(\${1}) -80)",$heb );
?>
<?php
$heb = 'put hebrew text here';
$utf = preg_replace("/([\xE0-\xFA
?>
ASKER
I tried both headers and it work.
Now it also adds the headers to the email content and it doesn't look so good.
Something is wrong here. I added also the 'From:' to the headers and I don't see it in the email title (It is empty) but I get it in the body as:
Content-type: text/html; charset=iso-8859-1
From: MyTree <info@vapisoft.com>
X-Mailer: PHP/5.2.6-pl7-gentoo
Message-Id: <20100902075622.8FAF7B152@ mx1.lingoc om.com>
Date: Thu, 2 Sep 2010 10:56:22 +0300 (IDT)
X-Spam-Prev-Subject: ¿”¿•¿“¿¢¿” ¿¿¿¿¿¿™¿™¿˜¿¨¿™
Now it also adds the headers to the email content and it doesn't look so good.
Something is wrong here. I added also the 'From:' to the headers and I don't see it in the email title (It is empty) but I get it in the body as:
Content-type: text/html; charset=iso-8859-1
From: MyTree <info@vapisoft.com>
X-Mailer: PHP/5.2.6-pl7-gentoo
Message-Id: <20100902075622.8FAF7B152@
Date: Thu, 2 Sep 2010 10:56:22 +0300 (IDT)
X-Spam-Prev-Subject: ¿”¿•¿“¿¢¿” ¿¿¿¿¿¿™¿™¿˜¿¨¿™
ASKER
To: actionmanager
I tried it and it doesn't work.
I understannd that you want to convert it from utf8, but the 'collation' in the table is 'utf8'.
I tried it and it doesn't work.
I understannd that you want to convert it from utf8, but the 'collation' in the table is 'utf8'.
try below
$text = 'put hebrew text here';
$text = mb_convert_encoding(trim($ text), 'HTML-ENTITIES', 'UTF-8');
$text = 'put hebrew text here';
$text = mb_convert_encoding(trim($
ASKER
To:
Now I get it like that (so I assume It does something)
יש לך תגו” 9;ה להו• 1;ע& #1492; שהש” 8;ר& #1514; במא• 7;י& #1496; 12;י \nל& #1512; 88;ו ת את התג• 3;ב& #1492; לחץ על הלי– 4;ק: \r\n\r\nhttp://www.vapisoft.com/MyTree/main.php?link=1,809.810|804.805|10.13|2.6,0,820,808,809:2:810:c85:52
Now I get it like that (so I assume It does something)
יש לך תגו”
wts the code for the mail compose, jsut paste it here. it need to set the content type as utf-8, and it will work.
in the HTML mail it need to have sopmething like this
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8“ >
Hope this helps
in the HTML mail it need to have sopmething like this
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8“ >
Hope this helps
Step 1) Set the HTML page charset encoding to utf8:
meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8“
Step 2) set the ‘collation’ attribute for the fields which are to accept hebrew text to: utf8_bin
Step 3) within your php script, right before calling the mysql_query function to insert the data into your DB, use both the utf8_encode function along with addslashes. This will encode the data into utf8 friendly characters.
Step 4) when pulling the text from the DB onto the page, make sure to use the utf8_decode along with stripslashes in order to display the data on the page.
hope this helps
meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8“
Step 2) set the ‘collation’ attribute for the fields which are to accept hebrew text to: utf8_bin
Step 3) within your php script, right before calling the mysql_query function to insert the data into your DB, use both the utf8_encode function along with addslashes. This will encode the data into utf8 friendly characters.
Step 4) when pulling the text from the DB onto the page, make sure to use the utf8_decode along with stripslashes in order to display the data on the page.
hope this helps
hehe shinug, you missed step 5,6,7,8 ;)
so there is a lot more to take care of when you handle international charsets like unicode
5) the header of the html page needs to specify the right codation. normally if you take HTML 4 strictly then the page falls back to not unicode as soon you have a not unicode char inside it
6) you have to have enabled the PHP extension "mbstring" - otherwise the standard string functions would "scramble" your utf8 codes (for example if you use split() on a utf8 string)
7) is to use the W3C validator at the html output. if there is ANY SINGLE non valid coded char in your output page then the (depending on the browser) it will show you question marks, or whatever.
8) you should test with more than 1 email client.. for example i wasted a lot of time to find out that outlook (up to 2007) can send utf8 text mails but cannot receive them .. so in outlook it happens that you get ???? in the subject line.. so better only use HTML mails (but maybe this comment is obsolete nowadays) ;)
9) if you get any strange html output then always use
http://validator.w3.org/
to find out if there are invalid characters in your page.
ah, i forgot step 10 : you need a lot of coffee and good luck! ;)
so there is a lot more to take care of when you handle international charsets like unicode
5) the header of the html page needs to specify the right codation. normally if you take HTML 4 strictly then the page falls back to not unicode as soon you have a not unicode char inside it
6) you have to have enabled the PHP extension "mbstring" - otherwise the standard string functions would "scramble" your utf8 codes (for example if you use split() on a utf8 string)
7) is to use the W3C validator at the html output. if there is ANY SINGLE non valid coded char in your output page then the (depending on the browser) it will show you question marks, or whatever.
8) you should test with more than 1 email client.. for example i wasted a lot of time to find out that outlook (up to 2007) can send utf8 text mails but cannot receive them .. so in outlook it happens that you get ???? in the subject line.. so better only use HTML mails (but maybe this comment is obsolete nowadays) ;)
9) if you get any strange html output then always use
http://validator.w3.org/
to find out if there are invalid characters in your page.
ah, i forgot step 10 : you need a lot of coffee and good luck! ;)
ASKER
To shinug:
1. I Inserted the text manually to the table from 'phpmyadmin'.
2. I set the collation as you wrote 'utf8_bin'
3. I added the utf_decode and the header (see attached code).
I get the following email.
Content-type: text/html; charset=UTF-8
Message-Id: <20100902100609.A39718D11@ mx1.lingoc om.com>
Date: Thu, 2 Sep 2010 13:06:09 +0300 (IDT)
From: apache@lingocom.com (apache)
X-Spam-Prev-Subject: ????? ????????
?? ?? ????? ?????? ?????? ????????\n????? ?? ?????? ??? ?? ?????:\r\n\r\nhttp://www.vapisoft.com/MyTree/main.php?link=1,809.810|804.805|10.13|2.6|16.738|1109.738,0,0,0,809:1:809:c85:57
1. I Inserted the text manually to the table from 'phpmyadmin'.
2. I set the collation as you wrote 'utf8_bin'
3. I added the utf_decode and the header (see attached code).
I get the following email.
Content-type: text/html; charset=UTF-8
Message-Id: <20100902100609.A39718D11@
Date: Thu, 2 Sep 2010 13:06:09 +0300 (IDT)
From: apache@lingocom.com (apache)
X-Spam-Prev-Subject: ????? ????????
?? ?? ????? ?????? ?????? ????????\n????? ?? ?????? ??? ?? ?????:\r\n\r\nhttp://www.vapisoft.com/MyTree/main.php?link=1,809.810|804.805|10.13|2.6|16.738|1109.738,0,0,0,809:1:809:c85:57
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$title = utf8_decode($text[1]); // mb_convert_encoding(trim($text[1]), 'HTML-ENTITIES', 'UTF-8');
$body = utf8_decode($text[2]); // mb_convert_encoding(trim($text[2]), 'HTML-ENTITIES', 'UTF-8');
mail ($user_mail, $title,$body,$headers);
just one question "off the discussion thread":
have you thought about saving hours and using a framework for this
like Zend Mail (Zend Framework)
http://framework.zend.com/manual/de/zend.mail.html
or phpMailer
http://phpmailer.worxware.com/
HTML MIME message encoding is really a time consuming game.. ins this case you really should think about not to invent the wheel for second millionst time.
have you thought about saving hours and using a framework for this
like Zend Mail (Zend Framework)
http://framework.zend.com/manual/de/zend.mail.html
or phpMailer
http://phpmailer.worxware.com/
HTML MIME message encoding is really a time consuming game.. ins this case you really should think about not to invent the wheel for second millionst time.
ASKER
OK, I am downloading phpMailer.I hope it will solve my problems.
It looks like a large code, is it also CPU consuming to use it?
I need something that will be quick enough so I can use it in a social-network with many simultaneous users (I use it to notify the user on a response their comments).
It looks like a large code, is it also CPU consuming to use it?
I need something that will be quick enough so I can use it in a social-network with many simultaneous users (I use it to notify the user on a response their comments).
try attached code
multiplemailer.zip
multiplemailer.zip
ASKER
Hi koolswans:
I tried the code. I run the: email_attachment_multiple. php and recived a page.
I filled the input boxes (without the attachment) and clicked the 'Sent' button.
I received "The website cannot display the page" error.
and received no mail.
I tried the code. I run the: email_attachment_multiple.
I filled the input boxes (without the attachment) and clicked the 'Sent' button.
I received "The website cannot display the page" error.
and received no mail.
specify your SMTP server in below line:
$mail->Host = "gmail.com";
$mail->Host = "gmail.com";
ASKER
Where do I do it?
I changed it (to vapisoft.com which is my server) and it didn't help (same problems).
I changed it (to vapisoft.com which is my server) and it didn't help (same problems).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Finally (after a long time) it works well.
Thank you very much.
I will incorporate it in my code and then Iwill give you the point (just in case I will run in to problems).
Thank you very much.
I will incorporate it in my code and then Iwill give you the point (just in case I will run in to problems).
ASKER
I am trying to include this in my PHP file.
When I include the include files (even without anything else) it doesn't execute the file.
I see that you are using the PHP mail function.
This means that don't need all this code I also copied your headers
so I think that my problem is the fetching of the text from the data base.
When I include the include files (even without anything else) it doesn't execute the file.
I see that you are using the PHP mail function.
This means that don't need all this code I also copied your headers
so I think that my problem is the fetching of the text from the data base.
ASKER
Thank you.
Now it works.
So the only way it works is via SMTP and via the php mail.
Now it works.
So the only way it works is via SMTP and via the php mail.
ah yes, still one thing: if you really want to use it "scalable" than you should write a kind of messaging queue service that runs in the background.. so best first to put the message into the database and then let a cronjob working in the background sending the messages to the recipients! at the beginning you can implement this cronjob using the phpmailer and later you can use a more performant mailer without changing the rest. ;)