質問編集履歴

2

タイトル

2018/08/08 06:26

投稿

tomo39-.
tomo39-.

スコア27

test CHANGED
@@ -1 +1 @@
1
- php mailer 添付ファイルだけが送信されてこない
1
+ php 添付ファイルだけが送信されてこない
test CHANGED
File without changes

1

コードを修正しました。

2018/08/08 06:26

投稿

tomo39-.
tomo39-.

スコア27

test CHANGED
File without changes
test CHANGED
@@ -24,40 +24,172 @@
24
24
 
25
25
  ```ここに言語を入力
26
26
 
27
- //添付ファイル追加
27
+ <?php
28
28
 
29
- $file1 = uploadFile($_FILES['file1']);
29
+ $error = 0;
30
30
 
31
- if ( $file1['error'] ) {
31
+ $to= "1hightouch@gmail.com";
32
32
 
33
+ $senderEmail = filterInput($_POST['email']);
34
+
35
+ $name = filterInput($_POST['name']);
36
+
37
+ $message = filterInput($_POST['message']);
38
+
39
+ $subject = filterInput($_POST['subject']);
40
+
41
+ $attachment = $_FILES['file']['tmp_name'];
42
+
43
+ $attachment_name = $_FILES['file']['name'];
44
+
45
+ die('test');
46
+
47
+
48
+
49
+ function filterInput($data)
50
+
51
+ {
52
+
53
+ $data = trim($data);
54
+
55
+ $data = stripslashes($data);
56
+
57
+ $data = htmlspecialchars($data);
58
+
59
+ return $data;
60
+
61
+ }
62
+
63
+ if( isset( $_FILES[ 'file' ] )){
64
+
65
+
66
+
67
+ $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
68
+
69
+ $filename = $_FILES['file']['name'];
70
+
71
+
72
+
73
+ $allowed = array('gif','png' ,'jpg');
74
+
75
+ $filename = $_FILES['file']['name'];
76
+
77
+ $ext = pathinfo($filename, PATHINFO_EXTENSION);
78
+
79
+ if(!in_array($ext,$allowed) ) {
80
+
81
+ ?>
82
+
83
+ <script type="text/javascript">
84
+
85
+
86
+
87
+ window.location = 'index.php?error=1';
88
+
33
- // TODO: エラー処理
89
+ </script>
90
+
91
+ <?php
92
+
93
+ }
94
+
95
+ if($_FILES["file"]["size"] < 5120000 ) {
96
+
97
+ ?>
98
+
99
+ <script type="text/javascript">
100
+
101
+
102
+
103
+ window.location = 'index.php?error=2';
104
+
105
+ </script>
106
+
107
+ <?php
108
+
109
+ }
110
+
111
+ $_FILES["imagefile"]["size"] < 2120000
112
+
113
+ $boundary =md5(date('r', time()));
114
+
115
+
116
+
117
+ $headers = "From: ". $senderEmail ."\r\nReply-To: ". $senderEmail ."";
118
+
119
+ $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
120
+
121
+
122
+
123
+ $message .="This is a multi-part message in MIME format.
124
+
125
+
126
+
127
+ --_1_$boundary
128
+
129
+ Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
130
+
131
+
132
+
133
+ --_2_$boundary
134
+
135
+ Content-Type: text/plain; charset=\"iso-8859-1\"
136
+
137
+ Content-Transfer-Encoding: 7bit
138
+
139
+
140
+
141
+ $message
142
+
143
+
144
+
145
+ --_2_$boundary--
146
+
147
+ --_1_$boundary
148
+
149
+ Content-Type: application/octet-stream; name=\"$filename\"
150
+
151
+ Content-Transfer-Encoding: base64
152
+
153
+ Content-Disposition: attachment
154
+
155
+
156
+
157
+ $attachment
158
+
159
+ --_1_$boundary--";
160
+
161
+
162
+
163
+ mail($to, $subject, $message, $headers);
164
+
165
+
166
+
167
+ }else{
168
+
169
+ $headers = "From: $senderEmail";
170
+
171
+ $semi_rand = md5(time());
172
+
173
+ $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
174
+
175
+ $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
176
+
177
+ @mail($to, $subject, $message, $headers);
178
+
179
+
34
180
 
35
181
  }
36
182
 
37
183
 
38
184
 
39
- $file2 = uploadFile($_FILES['file2']);
185
+ ?>
40
186
 
41
- if ( $file2['error'] ) {
187
+ <script type="text/javascript">
42
188
 
43
- // TODO: エラー処理
189
+
44
190
 
45
- }
191
+ window.location = 'index.php?msg=success';
46
192
 
47
-
48
-
49
- if ( $file1['path'] ) {
193
+ </script>
50
-
51
- $mail->addAttachment( $file1['path'], mb_encode_mimeheader( $file1['name'], $charset) );
52
-
53
- }
54
-
55
-
56
-
57
- if ( $file2['path'] ) {
58
-
59
- $mail->addAttachment( $file2['path'], mb_encode_mimeheader( $file2['name'], $charset) );
60
-
61
- }
62
194
 
63
195
  ```