Hello can someone please assist me?
I have a simple contact form with a radio button to select your town, I want the email to be send to a specific email address depending on the town they select, currently my contact form just send it to me.
I fthey select Cape town it must send to [email protected] if they select pretoria it must go to [email protected] etc etc
HTML:
PHP:
I have a simple contact form with a radio button to select your town, I want the email to be send to a specific email address depending on the town they select, currently my contact form just send it to me.
I fthey select Cape town it must send to [email protected] if they select pretoria it must go to [email protected] etc etc
HTML:
HTML:
<fieldset>
<!-- Form Name -->
<legend>Contact Us</legend>
<!-- Name input-->
<div class="form-group">
<label class="col-md-4 control-label" for="name">Name</label>
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="Enter Name Here" class="form-control input-md">
</div>
</div>
<!-- E-mail input-->
<div class="form-group">
<label class="col-md-4 control-label" for="email">E-mail</label>
<div class="col-md-4">
<input id="email" name="email" type="text" placeholder="Enter E-mail Here" class="form-control input-md">
</div>
</div>
<!-- Select Town -->
<div class="form-group">
<label class="col-md-4 control-label" for="town">Town</label>
<div class="col-md-4">
<select id="town" name="town" class="form-control">
<option value="Cape Town">Cape Town</option>
<option value="Bellville">Bellville</option>
<option value="Pretoria">Pretoria</option>
<option value="Johannesburg">Johannesburg</option>
</select>
</div>
</div>
<!-- Message -->
<div class="form-group">
<label class="col-md-4 control-label" for="message">Message</label>
<div class="col-md-4">
<textarea class="form-control" id="message" name="message" placeholder="Enter Message Here"></textarea>
</div>
</div>
</fieldset>
PHP:
PHP:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$town = $_POST['town'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "NichtComrade, you sneaky russian bear";
exit;
}
$email_from = '[email protected]';//<== My Email Address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "[email protected]";//<== My Email Address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>