質問するログイン新規登録

質問編集履歴

2

ソース追加

2016/07/04 02:59

投稿

rainbowsix
rainbowsix

スコア102

title CHANGED
File without changes
body CHANGED
@@ -20,4 +20,172 @@
20
20
  PHPメールフォームを作成しています。
21
21
  yahooやgmailなどではなんの問題なく表示されますが。
22
22
  会社のメーラー(Becky!)では上記のようにヘッダー情報などが本文に出てしまいます。
23
- 何が問題だと考えられますか?
23
+ 何が問題だと考えられますか?
24
+
25
+ ソースを追加すると
26
+ ```becky!未対応
27
+ public function adminSend() {
28
+ // 送信先の設定
29
+ foreach ($this->adminArray as $value) {
30
+ $this->sendMail[] = mb_encode_mimeheader($this->adminName, "ISO-2022-JP-MS","UTF-8") ." <" . trim($value) . ">";
31
+ }
32
+
33
+ // タイトルの設定
34
+ $this->sendTitle = "{$this->requiredItem["name"]}様よりお問い合わせ";
35
+ $this->sendTitle = mb_encode_mimeheader($this->sendTitle, "ISO-2022-JP-MS","UTF-8");
36
+
37
+ // メッセージの設定
38
+ $this->sendMessage = "{$this->requiredItem["name"]}様より、下記内容でお問い合わせが届いています。\n";
39
+ $this->sendMessage .= "\n";
40
+ foreach ($this->submitContent as $key => $value) {
41
+ $this->sendMessage .= "■{$key}\n";
42
+ $this->sendMessage .= "{$value}\n\n";
43
+ }
44
+ $this->sendMessage .= "\n\n";
45
+ $this->sendMessage .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
46
+ $this->sendMessage .= "[送信日時]".date("Y年m月d日(D) H時i分s秒")."\n";
47
+ $this->sendMessage .= "[IPアドレス]{$this->server["REMOTE_ADDR"]}\n";
48
+ $this->sendMessage .= "[ホスト]{$this->server["REMOTE_HOST"]}\n";
49
+ $this->sendMessage .= "[USER_AGENT]{$this->server["HTTP_USER_AGENT"]}\n";
50
+ $this->sendMessage .= "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
51
+ $this->sendMessage = mb_convert_encoding($this->sendMessage, "ISO-2022-JP-MS","UTF-8");
52
+
53
+ //ヘッダーの設定
54
+ $this->sendHeaders = "X-Mailer: PHP5\r\n";
55
+ $this->sendHeaders = "MIME-Version: 1.0\r\n";
56
+ $this->sendHeaders .= "From: ".mb_encode_mimeheader($this->requiredItem["name"], "ISO-2022-JP-MS","UTF-8") ." <{$this->requiredItem["mailaddress"]}> \r\n";
57
+ $this->sendHeaders .= "Content-Transfer-Encoding: 7bit\r\n";
58
+
59
+ // 添付ファイルの設定
60
+ if (!empty($this->submitFile)) {
61
+ $this->sendHeaders .= "Content-type: multipart/mixed; boundary=\"{$this->boundary}\" \r\n";
62
+
63
+ $tmpMessage = $this->sendMessage;
64
+
65
+ $this->sendMessage = "--{$this->boundary}\n";
66
+ $this->sendMessage .= "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n";
67
+ $this->sendMessage .= "Content-Transfer-Encoding: 7bit\n\n";
68
+ $this->sendMessage .= $tmpMessage."\n";
69
+
70
+ foreach ($this->submitFile as $key => $value) {
71
+ foreach ($value as $key2 => $value2) {
72
+ $name = $key2;
73
+ $f_encoded = $value2;
74
+
75
+ $this->sendMessage .= "\n";
76
+ $this->sendMessage .= "--{$this->boundary}\n";
77
+ $this->sendMessage .= "Content-Type: application/octet-stream; ";
78
+ $this->sendMessage .= "charset=\"ISO-2022-JP\" ";
79
+ $this->sendMessage .= "name=\"".mb_encode_mimeheader($name, "ISO-2022-JP-MS","UTF-8")."\"\n";
80
+ $this->sendMessage .= "Content-Transfer-Encoding: base64\n";
81
+ $this->sendMessage .= "Content-Disposition: attachment; ";
82
+ $this->sendMessage .= "filename=\"".mb_encode_mimeheader($name, "ISO-2022-JP-MS","UTF-8")."\"\n";
83
+ $this->sendMessage .= "\n";
84
+ $this->sendMessage .= "{$f_encoded}\n";
85
+ }
86
+ }
87
+
88
+ $this->sendMessage .= "--{$this->boundary}--\n";
89
+
90
+ } else {
91
+ $this->sendHeaders .= "Content-type: text/plain; charset=\"ISO-2022-JP\" \r\n";
92
+ }
93
+
94
+ // メールの送信 (宛先, 件名, 本文, 送り主(From:が必須))
95
+ foreach ($this->sendMail as $send) {
96
+ @mail($send, $this->sendTitle, $this->sendMessage, $this->sendHeaders);
97
+ }
98
+ }
99
+ ```
100
+ ```becky!でもファイル1個は問題なく受信できたソース
101
+ function sendmail_jpn($to, $subject, $message, $from_email,$from_name, $filepath01, $filepath02)
102
+ {
103
+ $mime_type = "application/octet-stream";
104
+
105
+ // 添付ファイルのエンコード
106
+ $filename01 = basename($filepath01);
107
+ $filename02 = basename($filepath02);
108
+
109
+
110
+ // マルチパートなので、パートの区切り文字列を指定
111
+ $boundary = '----=_Boundary_' . uniqid(rand(1000,9999) . '_') . '_';
112
+
113
+ // 件名のエンコード
114
+ $subject = mb_convert_encoding($subject, 'ISO-2022-JP', 'auto');
115
+ $subject = mb_encode_mimeheader_ex($subject);
116
+
117
+ // 本文のエンコード
118
+ $message = mb_convert_encoding($message, 'ISO-2022-JP', 'auto');
119
+
120
+ // toをエンコード
121
+ // $to = mb_convert_encoding($mail['to']['name'], "auto", "auto");
122
+ $to = "=?ISO-2022-JP?B?" . base64_encode($to) . '?= <' . $to . '>';
123
+
124
+ // fromをエンコード
125
+ $from_name = mb_convert_encoding($from_name, 'ISO-2022-JP', 'auto');
126
+ $from = "=?ISO-2022-JP?B?" . base64_encode($from_name) . '?= <' . $from_email . '>';
127
+
128
+ // 添付ファイルのエンコード01
129
+ $filename01 = mb_convert_encoding($filename01, 'ISO-2022-JP', 'auto');
130
+ $filename01 = "=?ISO-2022-JP?B?" . base64_encode($filename01) . "?=";
131
+
132
+ // 添付ファイルのエンコード02
133
+ $filename02 = mb_convert_encoding($filename02, 'ISO-2022-JP', 'auto');
134
+ $filename02 = "=?ISO-2022-JP?B?" . base64_encode($filename02) . "?=";
135
+
136
+ // ヘッダーの指定
137
+ $head = "";
138
+ $head .= "From: {$from}\n";
139
+ $head .= "MIME-Version: 1.0\n";
140
+ $head .= "Content-Type: multipart/mixed; boundary=\"{$boundary}\"\n";
141
+ $head .= "Content-Transfer-Encoding: 7bit";
142
+
143
+ $body = "";
144
+
145
+ // 本文
146
+ $body .= "--{$boundary}\n";
147
+ $body .= "Content-Type: text/plain; charset=ISO-2022-JP;" .
148
+ "Content-Transfer-Encoding: 7bit\n";
149
+ $body .= "\n";
150
+ $body .= "{$message}\n";
151
+ $body .= "\n";
152
+
153
+ // 添付ファイルの処理01
154
+ $body .= "--{$boundary}\n";
155
+ $body .= "Content-Type: {$mime_type}; name=\"{$filename01}\"\n" .
156
+ "Content-Transfer-Encoding: base64\n" .
157
+ "Content-Disposition: attachment; filename=\"{$filename01}\"\n";
158
+ $body .= "\n";
159
+
160
+ $fp = fopen( $filepath01, "r" ) or die("Error on mailing. (attachment file cannot open)");
161
+ $contents01 = fread( $fp, filesize($filepath01) );
162
+ fclose( $fp );
163
+ $f_encoded01 = chunk_split(base64_encode($contents01)); //添付ファイルをbase64エンコードする
164
+
165
+ // 添付ファイルの処理02
166
+ $body .= "--{$boundary}\n";
167
+ $body .= "Content-Type: {$mime_type}; name=\"{$filename02}\"\n" .
168
+ "Content-Transfer-Encoding: base64\n" .
169
+ "Content-Disposition: attachment; filename=\"{$filename02}\"\n";
170
+ $body .= "\n";
171
+
172
+ $fp = fopen( $filepath02, "r" ) or die("Error on mailing. (attachment file cannot open)");
173
+ $contents02 = fread( $fp, filesize($filepath02) );
174
+ fclose( $fp );
175
+ $f_encoded02 = chunk_split(base64_encode($contents02)); //添付ファイルをbase64エンコードする
176
+
177
+ $body .= "{$f_encoded01}\n\r";
178
+ //var_dump($body);
179
+ $body .= "{$f_encoded02}\n";
180
+ $body .= "\n";
181
+
182
+
183
+
184
+ if (mail($to, $subject, $body, $head)) {
185
+ echo 'sendmail_jpn : OK.';
186
+ } else {
187
+ echo 'sendmail_jpn : FAILURE.';
188
+ }
189
+ }
190
+ ```
191
+ コードが長くて見難いですが一応追加しておきます。二つのコードのエンコードの仕方が違うみたいですが

1

修正

2016/07/04 02:59

投稿

rainbowsix
rainbowsix

スコア102

title CHANGED
File without changes
body CHANGED
@@ -1,3 +1,4 @@
1
+ ![イメージ説明](4d59752e901bd7b1ca063b5b2c1f58a4.jpeg)
1
2
  ```受信メール内容
2
3
  From: =?ISO-2022-JP?B?GyRCJUYlOSVIGyhC?= <hoge@hoge.com>
3
4