Click here to Skip to main content
15,902,846 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there!

I'm trying to create an html form and a php send mail, but my code is not working, I don't get any error, but the email is not sent.
What am I doing wrong?

What I have tried:

<form class="contact-form" id="contact" role="form">
					
										
					<div class="col-md-6">
						<input class="form-control input-box" id="name" type="text" name="name" placeholder="Name">
					</div>
					
					<div class="col-md-6">
						<input class="form-control input-box" id="email" type="email" name="email" placeholder="Email">
					</div>
					
					<div class="col-md-6">
						<input class="form-control input-box" id="subject" type="text" name="subject" placeholder="Subject">
						</div>
					<div class="col-md-6">
						<input class="form-control input-box" id="phone" type="text" name="phone" placeholder="Phone">
					</div>
					<div class="col-md-4">
					<input class="form-control input-select" type="radio" name="radio" id="radio" value="ident"> Pack 1 </div>
					<div class="col-md-4">
					<input class="form-control input-select" type="radio" name="radio" id="radio" value="identpro"> Pack 2</div>
					<div class="col-md-4">
					<input class="form-control input-select" type="radio" name="radio" id="radio" value="identweb"> Pack 3</div>
					
					<div class="col-md-12">
						<textarea class="form-control textarea-box" id="message" rows="8" placeholder="Menssage"></textarea>
					</div>
					
					<button class="btn btn-primary standard-button2 ladda-button" type="submit" id="submit" name="submit" data-style="expand-left">Send</button>
					
				</form>





<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['phone']) &&   isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
 
  // detect & prevent header injections
  $test = "/(content-type|bcc:|cc:|to:)/i";
  foreach ( $_POST as $key => $val ) {
    if ( preg_match( $test, $val ) ) {
      exit;
    }
  }
  
  //
	$body=$_POST['message'].$_POST['name'].$_POST['phone'] .$_POST['radio'];
	mail( "email@email.com", $_POST['subject'], $body, "From:" . $_POST['email']);
 
  //			^
}
?>
Posted
Comments
Mohibur Rashid 27-Feb-16 18:25pm    
is your smtp server configured?
Member 12356042 29-Feb-16 6:40am    
Hi there Mohibur Rashid, thank you for your answer!
Yes, I do. If I use just the last line "mail( "email@email.com", $_POST['subject'], $body, "From:" . $_POST['email']);" it works, but not with all code... I don't know what am I doing wrong :\
Mohibur Rashid 29-Feb-16 20:20pm    
piece of advice, try to build a habit of creating log. in preg_match there is a exit command. You should write some log. so, in case you don't get anything, you will have your log to tell about it. check if your php code is exiting before your mail function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900