Активиран ли е PHPMail() или SMTP? Дай малко конкретика.
Пробвай така:
<!DOCTYPE html>
<html>
<head>
<style>
/* Add your CSS styles here */
</style>
</head>
<body>
<section>
<div class="cta-from">
<form action="process-form.php" method="POST">
<div class="cta-form-col d-flex justify-content-between">
<select class="custom-select" name="service">
<option selected="">Select Service</option>
<option>Ambient Freight Transport Service</option>
<option>Frozen Freight Transport Service</option>
<option>Groupage Freight Transport Service</option>
<option>Full load Freight Transport Service</option>
<option>Part load Freight Transport Service</option>
<option>Part load Freight Transport Service</option>
<option>ADR "Dangerous" Freight Transport Service</option>
</select>
<input type="text" name="length" placeholder="Length">
<input type="text" name="height" placeholder="Height">
</div>
<div class="cta-form-col d-flex justify-content-between">
<select class="custom-select" name="from_country">
<option selected="">From Country</option>
<option value="United Kingdom">United Kingdom</option>
<!-- Add other options here -->
</select>
<select class="custom-select" name="to_country">
<option selected="">To Country</option>
<option value="United Kingdom">United Kingdom</option>
<!-- Add other options here -->
</select>
</div>
<div class="cta-form-col d-flex justify-content-between">
<select class="custom-select" name="weight">
<option selected="">Weight kg</option>
<option>100Kg</option>
<option>200Kg</option>
<option>300Kg</option>
<!-- Add other options here -->
</select>
<input class="cta-email" type="email" name="email" placeholder="Email ID">
<input class="cta-phone" type="tel" name="phone" placeholder="Phone Number">
</div>
<h4 class="extra-services"><i class="fas fa-binoculars"></i>How we can connect with you</h4>
<ul>
<li>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1" name="contact_by_phone">
<label class="custom-control-label" for="customCheck1">By Phone</label>
</div>
</li>
<li>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck2" name="contact_by_email">
<label class="custom-control-label" for="customCheck2">By Email</label>
</div>
</li>
<!-- Add other checkbox options here -->
</ul>
<button class="btn" type="submit">Contact us</button>
</form>
</div>
</section>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Collect form data
$service = $_POST['service'];
$length = $_POST['length'];
$height = $_POST['height'];
$fromCountry = $_POST['from_country'];
$toCountry = $_POST['to_country'];
$weight = $_POST['weight'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$contactByPhone = isset($_POST['contact_by_phone']);
$contactByEmail = isset($_POST['contact_by_email']);
// Validate form data
$errors = array();
if (empty($service)) {
$errors[] = 'Please select a service';
}
if (!is_numeric($length)) {
$errors[] = 'Length must be a number';
}
if (!is_numeric($height)) {
$errors[] = 'Height must be a number';
}
if (empty($fromCountry)) {
$errors[] = 'Please select a "from" country';
}
if (empty($toCountry)) {
$errors[] = 'Please select a "to" country';
}
if (empty($weight)) {
$errors[] = 'Please select a weight';
}
if (empty($email) && empty($phone)) {
$errors[] = 'Please provide an email or phone number';
}
// If there are no errors, send an email
if (empty($errors)) {
$to = '
[email protected]';
$subject = 'New contact request';
$message = "Service: $service\nLength: $length\nHeight: $height\nFrom: $fromCountry\nTo: $toCountry\nWeight: $weight\nEmail: $email\nPhone: $phone\nContact by phone: " . ($contactByPhone ? 'Yes' : 'No') . "\nContact by email: " . ($contactByEmail ? 'Yes' : 'No');
$headers = "From: $email\r\nReply-To: $email\r\nX-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
echo 'Thank you for your message. We will get back to you soon.';
} else {
// If there are errors, display them
echo '<ul>';
foreach ($errors as $error) {
echo "<li>$error</li>";
}
echo '</ul>';
}
}
?>
</body>
</html>