質問編集履歴
1
ソースを添付しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -25,3 +25,153 @@
|
|
25
25
|
しかしながら何が原因なのか推定が手詰まりになっています。添付データが破損する状況というのは、どのような原因が考えられますでしょうか。また推定するための方法などありますでしょうか。知見のある方がおりましたら、お教え願います。
|
26
26
|
|
27
27
|
よろしくお願い申し上げます。
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
すみません。返信に書いてしまいました。
|
32
|
+
|
33
|
+
送信部分のソースです。
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
//$subject:件名
|
38
|
+
|
39
|
+
//$message:メール本文
|
40
|
+
|
41
|
+
//$files:array(添付ファイル)
|
42
|
+
|
43
|
+
function sendmailFile($to,$from,$subject,$message,$files)
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
//マイムタイプ定義
|
48
|
+
|
49
|
+
$mime_content_types = array(
|
50
|
+
|
51
|
+
'pdf' => 'application/pdf',
|
52
|
+
|
53
|
+
);
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
//件名・本文をエンコード
|
58
|
+
|
59
|
+
$subject = mb_convert_encoding($subject, 'JIS', 'UTF-8');
|
60
|
+
|
61
|
+
$message = mb_convert_encoding($message, 'JIS', 'UTF-8');
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
$subject = '=?iso-2022-jp?B?' . base64_encode($subject) . '?=';
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
//バウンダリ文字列を定義
|
70
|
+
|
71
|
+
if (empty($files)) {
|
72
|
+
|
73
|
+
$boundary = null;
|
74
|
+
|
75
|
+
}else{
|
76
|
+
|
77
|
+
$boundary = md5(uniqid(rand(), true));
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
//メールボディを定義
|
84
|
+
|
85
|
+
if (empty($files)) {
|
86
|
+
|
87
|
+
$body = $message;
|
88
|
+
|
89
|
+
}else{
|
90
|
+
|
91
|
+
$body = "--$boundary\n";
|
92
|
+
|
93
|
+
$body .= "Content-Type: text/plain; charset=\"iso-2022-jp\"\n";
|
94
|
+
|
95
|
+
$body .= "Content-Transfer-Encoding: 7bit\n";
|
96
|
+
|
97
|
+
$body .= "\n";
|
98
|
+
|
99
|
+
$body .= "$message\n";
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
foreach($files as $file) {
|
104
|
+
|
105
|
+
if (!file_exists($file)) {
|
106
|
+
|
107
|
+
continue;
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
$info = pathinfo($file);
|
114
|
+
|
115
|
+
$content = $mime_content_types[$info['extension']];
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
$filename = basename($file);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
$body .= "\n";
|
124
|
+
|
125
|
+
$body .= "--$boundary\n";
|
126
|
+
|
127
|
+
$body .= "Content-Type: $content; name=\"$filename\"\n";
|
128
|
+
|
129
|
+
$body .= "Content-Disposition: attachment; filename=\"$filename\"\n";
|
130
|
+
|
131
|
+
$body .= "Content-Transfer-Encoding: base64\n";
|
132
|
+
|
133
|
+
$body .= "\n";
|
134
|
+
|
135
|
+
$body .= chunk_split(base64_encode(file_get_contents($file))) . "\n";
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
$body .= '--' . $boundary . '--';
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
//メールヘッダを定義
|
148
|
+
|
149
|
+
$header = "X-Mailer: PHP5\n";
|
150
|
+
|
151
|
+
$header .= "From: $from\n";
|
152
|
+
|
153
|
+
$header .= "MIME-Version: 1.0\n";
|
154
|
+
|
155
|
+
if (empty($files)) {
|
156
|
+
|
157
|
+
$header .= "Content-Type: text/plain; charset=\"iso-2022-jp\"\n";
|
158
|
+
|
159
|
+
}else{
|
160
|
+
|
161
|
+
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
$header .= "Content-Transfer-Encoding: 7bit";
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//メール送信
|
170
|
+
|
171
|
+
$flg = mail($to, $subject, $body, $header);
|
172
|
+
|
173
|
+
error_log("sendmailFile TO:{$to} SUB:{$subject} RES:{$flg} DATE=".DATE("Y/m/d H:i:s")."\n", 3, '/var/www/html/egogram/maillog');
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
```
|