-2

I've setup a form which emails me the post values and I was wondering if I could use IF commands or something similar to email a different account.

here is the html what would I need for the php ?

<form  id="my-contact-form" action="contacts.php" method="post"  role="form"> 
<div><input " name="my-contact-form" type="hidden" value="1"  class="form-control"></div> 
<fieldset> 
<legend>Fill in this form to contact me</legend> 
<label for="username">Your name : </label> 
<input class="u-full-width" style="color:black" id="username" name="username" type="text" value="" > 
<label for="useremail">Your email : </label> 
<input class="u-full-width" style="color:black" id="useremail" name="useremail" type="email" value="" > 
<label for="userphone">Your phone : </label> 
<input style="color:black" id="userphone" name="userphone" type="text" value="" > <br>
<label for="reply">Best way to contact you : </label>
<input type="radio" id="reply" name="reply" value="phone">phone
<input type="radio"  name="reply" value="email">email
<label for="subject">Subject : </label> 
<select style="color:black" id="subject" name="subject" > 
<option value="Support" >Support</option> 
<option value="Sales" >Sales</option> 
<option value="Other" >Other</option> 
</select>
 
<button type="submit"  name="submit-btn" value="1" style="color:white" class="btn btn-success">Submit</button> 

</div>

1 Answers1

0

The below code is what you should use to chose the email. Change the emails to which ones you want to use. Then $email is the saved email and use that to use that email for the email.

<?php

$subject = $_POST['subject'];

if($subject == 'sales'){
    $email = "sales@example.com";
} else if($subject == 'support'){
    $email = "support@example.com";
} else {
    $email = "other@example.com";
}

?>

Then to make it send to that email place:

<?php echo $email; ?> 

where you want the email to show to make it send. But if you have a php mail system then just place $email.

Very basic but should help you get on your way.