Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP UTF8 mail gets garbled on iPhone mail app

I am using php internal mail function to send mail, I wrapped it up in a function which UTF8 the process, I found it online.

it works, I sent the email in the code to my GMAIL and to my EXCHANGE server, both in GMAIL and my Outlook client on my PC I get the message just right.

My iPhone is also connected to the exchange and GMAIL accounts, so I get both messages on my iPhone. the iPhone receives the GMAIL message correctly, but the EXCHANGE account shows the message with garbled gibberish text where no-latin characters are.

the example bellow sends Hebrew characters in the subject and in the body. On my iPhone, the subject gets received correctly in Hebrew, but the Hebrew parts in the body of the message are garbled.

can anyone comment on that ? maybe try it on your own setup ?

thanks,

<?php


function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') { 
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' .   "\r\n"; 
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);  
}

$mymessage = "Hello <BR>"; 
$mymessage.= "Received: now<BR/><BR/>";
$mymessage.= "details: שלום שלום<BR/><BR/>";

mail_utf8 ("[email protected],[email protected]", "שלום", $mymessage, "my_mail", "[email protected]");


?>
like image 769
Moshe Marciano Avatar asked Mar 04 '11 12:03

Moshe Marciano


People also ask

Why is my email lagging on my iPhone?

Slow incoming email on an iPhone may be due to problems with your network connections or a glitch that is making the iPhone run slowly. Troubleshoot connections to try to speed up downloads. If this doesn't work, try fixes on the Mail app, the email account and the iPhone's network connections.

How do I make an email high importance on iPhone?

To flag an important email in iPhone Mail or iPad Mail: Open the email in the Mail app. Select the Reply icon, then choose Flag. Other options include Mark as Unread, Move to Junk, and Notify Me, which notifies you when someone replies to an email thread.


1 Answers

Because the message is correctly received on your gmail account through your iPhone this is probably a bug/misconfiguration on the exchange server or in the iPhone Exchange synchronisation.

The best thing to do would be to base64 encode not only the subject but the whole message: the characters base64 uses are almost always transferred correctly since the character codes are the same in US-ASCII, ISO-8859-x and UTF-8. All modern mail clients can decode base64, but it does increase the size of your message by about 33%.

 function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') { 
      $header_ = 'MIME-Version: 1.0' . "\r\n" .
                 'Content-type: text/plain; charset=UTF-8' .   "\r\n" .
                 'Content-Transfer-Encoding: base64' . "\r\n"; 
      mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', base64_encode($message), $header_ . $header);  
 }
like image 81
dtech Avatar answered Oct 02 '22 09:10

dtech