How do I send emails with Arabic content via PHP's mail function?
문제
I'm having a challenge with sending emails with arabic content using PHP's mail function. Let's say I have this simple arabic string:
بريد
I've tried several ways to utilize the headers, but the emails content all still end up with something like: X*X1X(X1Y X/
. However, the email subject is correctly encoded if I use arabic characters (thanks to the base64_encode, see function below)
Here's one of the email functions I've tried
function sendSimpleMail($to,$from,$subject,$message) {
$headers = 'MIME-Version: 1.0' ."\r\n";
$headers .= 'To: '.$to ."\r\n";
$headers .= 'From: '.$from . "\r\n";
$headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'."\r\n";
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=',$message, $headers);
}
Any suggestions on alternative ways to achieve this goal?
해결책
Unfortunately, 8bit
encoding is not reliable in e-mail. Many mail transport agents will remove the top bit of every byte in the mail body. بريد
is "\xD8\xA8\xD8\xB1\xD9\x8A\xD8\xAF"
in UTF-8 bytes; remove the top bit from those bytes and you get ASCII "X(X1Y\nX/"
.
The way to get non-ASCII characters into a mail body is to set Content-Transfer-Encoding
to either base64
or quoted-printable
, and the encode the body with base64_encode
or quoted_printable_encode
, respectively.
(quoted-printable
is better if the mail is largely ASCII as it retains readability in the encoded form and is more efficient for ASCII. If the whole mail is Arabic, base64
would probably be the better choice.)
다른 팁
라인을 선택하기 전에 ()
$this->Property->PropertyImage->save(...)
.
콜
$this->Property->PropertyImage->create();
.
모델이 방금 저장된 것과 계속해서 작동하는 대신 새로운 레코드를 작성하도록 알려줍니다.
Try this
$headers .= 'From: =?UTF-8?B?'.base64_encode($from). "\r\n";
다른 사람들이 당신이 그들을주는 DLL에 소스 코드를 엔지니어에게 리버스로 되돌릴 수 없도록, 당신은 그들을주는 것, 당신은 dll을 난독 화해야합니다. .NET 난독 화를 참조하십시오.