1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
<?php
use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception;
require 'PHPMailer-6.0.7/src/Exception.php'; require 'PHPMailer-6.0.7/src/PHPMailer.php'; require 'PHPMailer-6.0.7/src/SMTP.php';
// error_reporting(0); // ini_set('display_errors', 0);
if ( ! function_exists('_h')) { function _h($str) { return htmlspecialchars($str); } }
if (empty($_POST)) { exit('No data'); } $attachment = ''; if(isset($_FILES['attachment'])){ $errors= array(); $file_name = $_FILES['attachment']['name']; $file_size =$_FILES['attachment']['size']; $file_tmp =$_FILES['attachment']['tmp_name']; $file_type=$_FILES['attachment']['type'];
$file_ext=strtolower(end(explode('.',$file_name)));
$extensions= array("jpeg","jpg","png","pdf");
if(in_array($file_ext,$extensions)=== false){ $errors[]="extension not allowed, please choose a JPEG , PDF or PNG file."; }
if($file_size > 2097152){ $errors[]='File size must be less than 2 MB'; }
if(empty($errors)){ move_uploaded_file($file_tmp,"file/".$file_name); $attachment = "file/".$file_name; }else{ print_r($errors); } } if(!filter_var($_POST['mail'],FILTER_VALIDATE_EMAIL)){ exit("Invalid email"); } $from = _h($_POST['mail']);
try {
$mail = new PHPMailer; // $mail->isSendmail(); // $mail->Host = 'localhost';
//Server settings $mail->SMTPDebug = 2; // Enable verbose debug output $mail->isSMTP(); $mail->Host = 'localhost'; // Set mailer to use SMTP // $mail->Host = 'mail.stradivariwettbewerb.com'; // Specify main and backup SMTP servers // $mail->SMTPAuth = TRUE; // Enable SMTP authentication // $mail->Username = 'admin@stradivariwettbewerb.com'; // SMTP username // $mail->Password = '2Tv@#230'; // SMTP password // $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted // $mail->Port = 25; // TCP port to connect to
//Recipients $mail->setFrom($from); // $mail->addAddress('nickcheung@onesolution.com.hk'); $mail->addAddress('monicalelehk@gmail.com'); // Add a recipient $mail->addBCC('manfok@onesolution.com.hk');
if ( ! empty($attachment)) { $mail->addAttachment($attachment); // Add attachments }
// Content $mail->isHTML(TRUE); // Set email format to HTML $mail->Subject = '小手牽大手音樂夏令營報名表';
ob_start(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>小手牽大手音樂夏令營報名表</title> </head> <body> <table width="100%"> <tr> <th>姓名</th> <td><?= _h($_POST['name']) ?></td> </tr> <tr> <th>性別</th> <td><?= $_POST['gender'] == 'male' ? '男' : '女' ?></td> </tr> <tr> <th>出生日期</th> <td><?= date('Y-m-d', strtotime($_POST['dob'])) ?></td> </tr> <tr> <th>手機號</th> <td><?= _h($_POST['mobile']) ?></td> </tr> <tr> <th>微信號</th> <td><?= _h($_POST['wechatno']) ?></td> </tr> <tr> <th>Email</th> <td><?= _h($_POST['mail']) ?></td> </tr> <tr> <th>學校或工作單位</th> <td><?= _h($_POST['organization']) ?></td> </tr> <tr> <th>家庭/通訊地址</th> <td><?= _h($_POST['address']) ?></td> </tr> <tr> <th>護照號</th> <td><?= _h($_POST['passportno']) ?></td> </tr> <tr> <th>護照有效期</th> <td><?= _h($_POST['passportValid']) ?></td> </tr> <tr> <th>護照複印件</th> <td>附件</td> </tr> <tr> <th>付款日期</th> <td><?= _h($_POST['paymentDate']) ?></td> </tr> <tr> <th>付款憑證</th> <td><?= _h($_POST['paymentCode']) ?></td> </tr> <tr> <th>付款人姓名</th> <td><?= _h($_POST['payer']) ?></td> </tr> <tr> <th>專業選項</th> <td><?php switch ($_POST['profession']) { case 'piano': echo '鋼琴'; break; case 'string': echo '弦樂器'; break; case 'vocal': echo '聲樂組'; break; case 'chamber': echo '室内樂'; break; } ?></td> </tr> <tr> <th>專業水平</th> <td><?= _h($_POST['professionLV']) ?></td> </tr> <tr> <th>到達瑞士日期</th> <td><?= date('Y-m-d', strtotime($_POST['arrivalDate'])) ?></td> </tr> <tr> <th>到達航班</th> <td><?= _h($_POST['arrivalFlight']) ?></td> </tr> <tr> <th>離開瑞士日期</th> <td><?= date('Y-m-d', strtotime($_POST['leaveDate'])) ?></td> </tr> <tr> <th>離開航班</th> <td><?= _h($_POST['departureFlight']) ?></td> </tr> </table> </body> </html> <?php
$body = ob_get_clean(); $mail->CharSet = 'UTF-8'; $mail->Body = $body; if($mail->send()) { echo '<script>alert("報名表已發送");window.location.href="index.php";</script>'; }else{ exit("發送失敗"); } // echo 'Message has been sent'; } catch (Exception $e) { echo '<script>alert("發送失敗: '.$mail->ErrorInfo.'");history.back()</script>'; // echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }
|