Skip to content

Instantly share code, notes, and snippets.

@sakadonohito
Last active December 28, 2015 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakadonohito/7450823 to your computer and use it in GitHub Desktop.
Save sakadonohito/7450823 to your computer and use it in GitHub Desktop.
FuelPHPのEmailパッケージを使ってファイルを添付する時の文字化け対策
<?php
public function sendmail($mail_info){
$email = \Email::forge();
$mail->from($mail_info['from']);
$mail->to($mail_info['to']);
$mail->cc($mail_info['cc']);
$mail->subject(mb_convert_kana($mail_info['subject'],"KV"));//件名に半角カナが含まれた場合を考慮して全角カナに変換
//最初の引数はファイルを見つけるためにも使うのでそのまま、通常は第1引数のみ。文字化け対策に別名用引数の第5引数にエンコードした添付ファイル名を渡す
if(array_key_exists("attach",$mail_info)) $mail->attach($file_info['attach'],false,null,null,mb_convert_encoding($file_info['attach'],"ISO-2022-JP","CP932"));
$mail->body(mb_convert_encoding($mail_info['body'],"ISO-2022-JP"));
$mail->send();
//本当は例外処理とかするのん
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment