'your-email@example.com', 'bcc' => '', 'from' => 'no-reply@example.com', 'from_name' => 'mail sender', 'smtp_host' => 'smtp.example.com', 'smtp_port' => 587, 'smtp_username' => 'your-username', 'smtp_password' => 'your-password', 'debug' => false, 'page_title' => 'Support Request Form', 'fields' => [ [ 'name' => 'requestor_name', 'type' => 'text', 'label' => 'Requestor Name', 'required' => true, ], [ 'name' => 'requestor_phone', 'type' => 'text', 'label' => 'Requestor Phone', 'required' => false, ], [ 'name' => 'requestor_email', 'type' => 'email', 'label' => 'Requestor Email', 'required' => true, ], [ 'name' => 'checkbox_example', 'type' => 'checkbox', 'label' => 'Checkbox Example', 'required' => false, ], [ 'name' => 'select_example', 'type' => 'select', 'label' => 'Select Example', 'required' => true, 'options' => [ '1' => 'option 1', '2' => 'option 2', ], ], [ 'name' => 'attachments', 'type' => 'file', 'label' => 'Attachments', 'required' => false, 'multiple' => true, // Support multiple files ], ], 'success_message' => 'Your request has been sent successfully!', ] EOD; if (file_put_contents($config_file, $default_config) === false) { die('Error: Could not create the default config file. Please check your file permissions or create a config.php file manually. Here is an example:
' . htmlspecialchars($default_config) . '
'); } else { die('A default config file has been created at ' . $config_file . '. Please update it with your actual settings.'); } } $config = require($config_file); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $error = ''; // Validate required fields foreach ($config['fields'] as $field) { if ($field['required'] && empty($_POST[$field['name']])) { $error .= "The field '{$field['label']}' is required. "; } } if ($error) { // Error in form submission $error = "Please fill in all required fields."; } else { // Collect form data $message = ''; foreach ($config['fields'] as $field) { if ($field['type'] === 'file' && isset($_FILES[$field['name']])) { // Handle file attachments separately if ( $config['debug'] ) { echo "_FILES
" . print_r($_FILES, true) . "
"; } $attachments = $_FILES[$field['name']]; } else { $message .= "{$field['label']}: " . htmlspecialchars($_POST[$field['name']]) . "\n"; } } // Prepare to send email using PHPMailer $mail = new PHPMailer(true); try { // Server settings $mail->isSMTP(); $mail->Host = $config['smtp_host']; $mail->SMTPAuth = true; $mail->Username = $config['smtp_username']; $mail->Password = $config['smtp_password']; $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // if ignore_ssl is set to true, ignore SSL certificate verification if ($config['ignore_ssl']) { $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); } $mail->Port = $config['smtp_port']; // Set the sender's email address from the form if (!empty($_POST['requestor_email']) && !empty($_POST['requestor_name'])) { $mail->setFrom($_POST['requestor_email'], $_POST['requestor_name']); } else { $mail->setFrom($config['from'], $config['from_name']); } // Add recipient $mail->addAddress($config['to']); if (!empty($config['bcc'])) { $bccs = explode(',', $config['bcc']); foreach ($bccs as $bcc) { $mail->addBCC($bcc); } } // Add reply-to address if (!empty($_POST['requestor_email']) && !empty($_POST['requestor_name'])) { $mail->AddReplyTo($_POST['requestor_email'], $_POST['requestor_name']); } // Email subject and body $mail->Subject = htmlspecialchars($_POST['short_description']); $mail->Body = $message; // Attach files if any if (!empty($attachments)) { if ($config['debug']) { echo "Attachments:
" . print_r($attachments, true) . "
"; } if (is_array($attachments['name'])) { for ($i = 0; $i < count($attachments['name']); $i++) { if ($config['debug']) { echo "Processing Attachment.
"; echo $attachments['name'][$i]; } // Only send if the attachment uploaded OK if ($attachments['error'][$i] !== UPLOAD_ERR_OK) { continue; } $mail->addAttachment($attachments['tmp_name'][$i], $attachments['name'][$i]); } } } // Send the email $mail->send(); echo $config['success_message']; } catch (Exception $e) { echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } } } ?> <?php echo htmlspecialchars($config['page_title']); ?>

" value="">