File: /home/exclusivehealthinsurancepartners/public_html/assets/php/contact_mail.php
<?php
// Email configuration
$toEmail = '[email protected]';
$fromName = 'Sender Name';
$formEmail = '[email protected]';
$postData = $statusMsg = $valErr = '';
$status = 'error';
// If the form is submitted
if(isset($_POST['submit'])){
// Get the submitted form data\
$postData = $_POST;
$firstname = trim($_POST['firstname']); .
$lastname = trim($_POST['lastname']);
$phone = trim($_POST['phone']);
$email = trim($_POST['email']);
$street = trim($_POST['street']);
$zipcode = trim($_POST['zipcode']);
$city = trim($_POST['city']);
$name = trim($_POST['state']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
// Validate form fields
if(empty($name)){
$valErr .= 'Please enter your name.<br/>';
}
if(empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false){
$valErr .= 'Please enter a valid email.<br/>';
}
if(empty($subject)){
$valErr .= 'Please enter subject.<br/>';
}
if(empty($message)){
$valErr .= 'Please enter your message.<br/>';
}
if(empty($valErr)){
// Send email notification to the site admin
$subject = 'New contact request submitted';
$htmlContent = "
<h2>Contact Request Details</h2>
<p><b>First Name: </b>".$firstname."</p>
<p><b>Last Name: </b>".$lastname."</p>
<p><b>Phone: </b>".$phone."</p>
<p><b>Email: </b>".$email."</p>
<p><b>Zipcode: </b>".$zipcode."</p>
<p><b>city: </b>".$city."</p>
<p><b>State: </b>".$state."</p>
<p><b>Subject: </b>".$subject."</p>
<p><b>Message: </b>".$message."</p>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// Header for sender info
$headers .= 'From:'.$fromName.' <'.$formEmail.'>' . "\r\n";
// Send email
@mail($toEmail, $subject, $htmlContent, $headers);
$status = 'success';
$statusMsg = 'Thank you! Your contact request has submitted successfully, we will get back to you soon.';
$postData = '';
}else{
$statusMsg = '<p>Please fill all the mandatory fields:</p>'.trim($valErr, '<br/>');
}
}