| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| - |
|
2 |
|
| 2 |
// File version 0.4
|
3 |
// File version 0.5
|
| 3 |
// Load PHPmailer
|
4 |
// Load PHPmailer
|
| 4 |
use PHPMailer\PHPMailer\PHPMailer;
|
5 |
use PHPMailer\PHPMailer\PHPMailer;
|
| 5 |
use PHPMailer\PHPMailer\Exception;
|
6 |
use PHPMailer\PHPMailer\Exception;
|
| 6 |
|
7 |
|
| 7 |
require 'PHPMailer/Exception.php';
|
8 |
require 'PHPMailer/Exception.php';
|
| Line 97... |
Line 98... |
| 97 |
// Collect form data
|
98 |
// Collect form data
|
| 98 |
$message = '';
|
99 |
$message = '';
|
| 99 |
foreach ($config['fields'] as $field) {
|
100 |
foreach ($config['fields'] as $field) {
|
| 100 |
if ($field['type'] === 'file' && isset($_FILES[$field['name']])) {
|
101 |
if ($field['type'] === 'file' && isset($_FILES[$field['name']])) {
|
| 101 |
// Handle file attachments separately
|
102 |
// Handle file attachments separately
|
| - |
|
103 |
echo "_FILES <pre>" . print_r($_FILES, true) . "</pre>";
|
| 102 |
$attachments[] = $_FILES[$field['name']];
|
104 |
$attachments = $_FILES[$field['name']];
|
| 103 |
} else {
|
105 |
} else {
|
| 104 |
$message .= "{$field['label']}: " . htmlspecialchars($_POST[$field['name']]) . "\n";
|
106 |
$message .= "{$field['label']}: " . htmlspecialchars($_POST[$field['name']]) . "\n";
|
| 105 |
}
|
107 |
}
|
| 106 |
}
|
108 |
}
|
| 107 |
|
109 |
|
| 108 |
// Prepare to send email using PHPMailer
|
110 |
// Prepare to send email using PHPMailer
|
| 109 |
$mail = new PHPMailer();
|
111 |
$mail = new PHPMailer();
|
| 110 |
try {
|
112 |
try {
|
| 111 |
if ($config['debug']) {
|
113 |
if ($config['debug']) {
|
| 112 |
$mail->SMTPDebug = 2; // Enable verbose debug output
|
114 |
$mail->SMTPDebug = 2; // Enable verbose debug output
|
| 113 |
}
|
115 |
}
|
| 114 |
$mail->isSMTP();
|
116 |
$mail->isSMTP();
|
| 115 |
$mail->SMTPOptions = array(
|
117 |
$mail->SMTPOptions = array(
|
| 116 |
'ssl' => array(
|
118 |
'ssl' => array(
|
| 117 |
'verify_peer' => false,
|
119 |
'verify_peer' => false,
|
| 118 |
'verify_peer_name' => false,
|
120 |
'verify_peer_name' => false,
|
| 119 |
'allow_self_signed' => true
|
121 |
'allow_self_signed' => true
|
| 120 |
)
|
122 |
)
|
| 121 |
);
|
123 |
);
|
| 122 |
$mail->Host = $config['smtp_host'];
|
124 |
$mail->Host = $config['smtp_host'];
|
| 123 |
$mail->SMTPAuth = true;
|
125 |
$mail->SMTPAuth = true;
|
| 124 |
$mail->Username = $config['smtp_username'];
|
126 |
$mail->Username = $config['smtp_username'];
|
| 125 |
$mail->Password = $config['smtp_password'];
|
127 |
$mail->Password = $config['smtp_password'];
|
| 126 |
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
128 |
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
| Line 140... |
Line 142... |
| 140 |
$mail->Subject = htmlspecialchars($_POST['short_description']);
|
142 |
$mail->Subject = htmlspecialchars($_POST['short_description']);
|
| 141 |
$mail->Body = $message;
|
143 |
$mail->Body = $message;
|
| 142 |
|
144 |
|
| 143 |
// Attach files if any
|
145 |
// Attach files if any
|
| 144 |
if (!empty($attachments)) {
|
146 |
if (!empty($attachments)) {
|
| - |
|
147 |
if ($config['debug']) {
|
| - |
|
148 |
echo "Attachments: <pre>" . print_r($attachments, true) . "</pre>";
|
| - |
|
149 |
}
|
| 145 |
foreach($attachments as $attachment) {
|
150 |
if (is_array($attachments['name'])) {
|
| - |
|
151 |
for ($i = 0; $i < count($attachments['name']); $i++) {
|
| - |
|
152 |
if ($config['debug']) {
|
| - |
|
153 |
echo "Processing Attachment.<br />";
|
| 146 |
echo $attachmment;
|
154 |
echo $attachments['name'][$i];
|
| - |
|
155 |
}
|
| - |
|
156 |
$mail->addAttachment($attachments['tmp_name'][$i], $attachments['name'][$i]);
|
| - |
|
157 |
}
|
| - |
|
158 |
} else {
|
| 147 |
$mail->addAttachment($attachment['tmp_name'], $attachment['name']);
|
159 |
$mail->addAttachment($attachments['tmp_name'], $attachments['name']);
|
| 148 |
}
|
160 |
}
|
| 149 |
}
|
161 |
}
|
| 150 |
|
162 |
|
| 151 |
$mail->send();
|
163 |
$mail->send();
|
| 152 |
$result = $config['success_message'];
|
164 |
$result = $config['success_message'];
|
| Line 242... |
Line 254... |
| 242 |
}
|
254 |
}
|
| 243 |
</style>
|
255 |
</style>
|
| 244 |
</head>
|
256 |
</head>
|
| 245 |
<body>
|
257 |
<body>
|
| 246 |
<div class="form-container">
|
258 |
<div class="form-container">
|
| 247 |
<?php if (isset($result)): ?>
|
259 |
<?php if (isset($result)): ?>
|
| 248 |
<div class="<?= $result_error ? 'message-error' : 'message-success' ?>">
|
260 |
<div class="<?= $result_error ? 'message-error' : 'message-success' ?>">
|
| 249 |
<?= htmlspecialchars($result) ?>
|
261 |
<?= htmlspecialchars($result) ?>
|
| 250 |
</div>
|
262 |
</div>
|
| 251 |
<?php endif; ?>
|
263 |
<?php endif; ?>
|
| 252 |
|
264 |
|
| 253 |
<?php if (isset($error) && !empty($error)): ?>
|
265 |
<?php if (isset($error) && !empty($error)): ?>
|
| 254 |
<div class="message-error">
|
266 |
<div class="message-error">
|
| 255 |
<?= htmlspecialchars($error) ?>
|
267 |
<?= htmlspecialchars($error) ?>
|
| 256 |
</div>
|
268 |
</div>
|
| 257 |
<?php endif; ?>
|
269 |
<?php endif; ?>
|
| 258 |
|
270 |
|
| 259 |
<h1><?php echo htmlspecialchars($config['page_title']); ?></h1>
|
271 |
<h1><?php echo htmlspecialchars($config['page_title']); ?></h1>
|
| 260 |
<form action="" method="POST" enctype="multipart/form-data">
|
272 |
<form action="" method="POST" enctype="multipart/form-data">
|
| 261 |
<div class="hidden-fields">
|
273 |
<div class="hidden-fields">
|
| 262 |
<input type="hidden" name="to" value="<?php echo htmlspecialchars($config['to']); ?>">
|
274 |
<input type="hidden" name="to" value="<?php echo htmlspecialchars($config['to']); ?>">
|
| 263 |
<input type="hidden" name="bcc" value="<?php echo htmlspecialchars($config['bcc']); ?>">
|
275 |
<input type="hidden" name="bcc" value="<?php echo htmlspecialchars($config['bcc']); ?>">
|
| 264 |
</div>
|
276 |
</div>
|
| 265 |
|
277 |
|
| 266 |
<?php foreach ($config['fields'] as $field): ?>
|
278 |
<?php foreach ($config['fields'] as $field): ?>
|
| 267 |
<div class="form-group">
|
279 |
<div class="form-group">
|
| 268 |
<label for="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required-field' : '' ?>">
|
280 |
<label for="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required-field' : '' ?>">
|
| 269 |
<?= htmlspecialchars($field['label']) ?>
|
281 |
<?= htmlspecialchars($field['label']) ?>
|
| 270 |
</label>
|
282 |
</label>
|
| 271 |
|
283 |
|
| 272 |
<?php if ($field['type'] == 'select'): ?>
|
284 |
<?php if ($field['type'] == 'select'): ?>
|
| 273 |
<select name="<?= htmlspecialchars($field['name']) ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>">
|
285 |
<select name="<?= htmlspecialchars($field['name']) ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>">
|
| 274 |
<?php foreach ($field['options'] as $value => $label): ?>
|
286 |
<?php foreach ($field['options'] as $value => $label): ?>
|
| 275 |
<option value="<?= htmlspecialchars($value) ?>"><?= htmlspecialchars($label) ?></option>
|
287 |
<option value="<?= htmlspecialchars($value) ?>"><?= htmlspecialchars($label) ?></option>
|
| 276 |
<?php endforeach; ?>
|
288 |
<?php endforeach; ?>
|
| 277 |
</select>
|
289 |
</select>
|
| 278 |
<?php elseif ($field['type'] == 'textarea'): ?>
|
290 |
<?php elseif ($field['type'] == 'textarea'): ?>
|
| 279 |
<textarea name="<?= htmlspecialchars($field['name']) ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>"></textarea>
|
291 |
<textarea name="<?= htmlspecialchars($field['name']) ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>"></textarea>
|
| 280 |
<?php else: ?>
|
292 |
<?php else: ?>
|
| 281 |
<input type="<?= htmlspecialchars($field['type']) ?>" name="<?= htmlspecialchars($field['name']) ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>">
|
293 |
<input type="<?= htmlspecialchars($field['type']) ?>" name="<?= htmlspecialchars($field['name']) ?><?= $field['multiple'] ? '[]' : '' ?>" id="<?= htmlspecialchars($field['name']) ?>" class="<?= $field['required'] ? 'required' : '' ?>" <?= $field['multiple'] ? 'multiple' : '' ?>>
|
| 282 |
<?php endif; ?>
|
294 |
<?php endif; ?>
|
| 283 |
</div>
|
295 |
</div>
|
| 284 |
<?php endforeach; ?>
|
296 |
<?php endforeach; ?>
|
| 285 |
|
297 |
|
| 286 |
<input type="submit" value="Submit">
|
298 |
<input type="submit" value="Submit">
|
| 287 |
</form>
|
299 |
</form>
|
| 288 |
</div>
|
300 |
</div>
|
| 289 |
</body>
|
301 |
</body>
|