プロが教える店舗&オフィスのセキュリティ対策術

xamppの開発環境を使っています。PHPでメール送信することまでは
できたのですが文章が文字化けしてしまい自分なりに調べて
試行錯誤してみたのですが結果変わらずで初心者なもので
いまいち原因がわからずで困っています^^;
長文となり申し訳ございませんが以下が調べた結果で
関係すると思われる箇所です。


【mail.php】
<html>
<head><title>mail.php</title></head>
<body>
<?php
$address=$_POST['address'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$header = "Content-Type: text/plain; charset=EUC-JP\n";
$header .= "From: 送信先@メールアドレス";

mb_language("Japanese");
if(mb_send_mail($address, $subject, mb_convert_encoding($message,"JIS","EUC-JP"),$header)){
print("送信完了しました。");
}else{
print("エラー:送信に失敗しました");
}
?>
</body>
</html>

【mail.html】
<html>
<head><title>メールの送信</title></head>
<body>
<h2>メールの送信</h2>
<form action="mail.php" method="post">
宛先:<input type="text" name="address"><br />
件名:<input type="text" name="subject"><br />
本文:<br /><textarea name="message" rows="5" cols="30"></textarea><br />
<input type="submit" value="送信">
</form>
</body>
</html>

【php.ini(xampp/apache/bin)】
[mbstring]
; language for internal character representation.
mbstring.language = Japanese

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
mbstring.internal_encoding = EUC-JP

; http input encoding.
mbstring.http_input = auto

; http output encoding. mb_output_handler must be
; registered as output buffer to function
mbstring.http_output = EUC-JP

; enable automatic encoding translation according to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
; portable libs/applications.
;mbstring.encoding_translation = Off

; automatic encoding detection order.
; auto means
;mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
;mbstring.substitute_character = none;

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
;mbstring.func_overload = 0

このような形なのですがどこが文字化けの原因なのでしょうか?
大変アバウトな感じで申し訳ないのですが
わかる方がおりましたら是非お力添えお願い致します。

A 回答 (1件)

まず【mail.php】【mail.html】ですが


<meta http-equiv="Content-Type" content="text/html; charset=euc-jp"/>
↑この様にきちんと文字コードを設定しましょう。

mb_convert_encoding($message,"JIS","EUC-JP"),$header)
↑本文の文字コードをeuc-jpからjisに変換していますが
$header = "Content-Type: text/plain; charset=EUC-JP\n";
↑ヘッダーはeuc-jpのままです。

文字コードは統一しておかないと文字化けして当然ですよ。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!