Categories: PHP

【PHP】CLI実行時のメール送信の文字化け対策

mbstringまわりの設定など普段.htaccessに設定を書いているのだが、
CLIで実行する時.htaccessを読み込まないので、別途設定が必要になる。
今回はその日本語の設定をしないがゆえにPEAR::Mailのメール送信にて文字化けがおきてしまったので、
文字化けを起こさないような対策を講じた。
詳細の対策は以下へ↓


やってることは.htaccessでやってることをini_setするだけ。
自分の環境では以下のような設定を行った。
mb_language(‘Japanese’);
ini_set(‘mbstring.detect_order’, ‘auto’);
ini_set(‘mbstring.http_input’ , ‘none’);
ini_set(‘mbstring.http_output’ , ‘none’);
ini_set(‘mbstring.input_encoding’, ‘pass’);
ini_set(‘mbstring.internal_encoding’, ‘UTF-8’);
ini_set(‘mbstring.language’, ‘Japanese’);
ini_set(‘mbstring.script_encoding’ , ‘UTF-8’);
ini_set(‘mbstring.substitute_character’, ‘none’);
ini_set(‘mbstring.encording_translation’, ‘0’);
とりあえず文字化けせずうまくいったのでバンザイ

mogmet

View Comments

  • まとめteみた.【【PHP】CLI実行時のメール送信の文字化け対策】

    mbstringまわりの設定など普段.htaccessに設定を書いているのだが、CLIで実行する時.htaccessを読み込まないので、別途設定が必要になる。今回はその日本語の設定をしないがゆえにPEAR::Mailのメール送信にて文字化けがおきてしまったので、文字化けを起こさないような対?...

  • とても魅力的な記事でした!!
    また遊びに来ます!!
    ありがとうございます。。

  • I don't think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

  • Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  • Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  • Thanks for sharing. I read many of your blog posts, cool, your blog is very good.

  • Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  • Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

Share
Published by
mogmet