Kavitha M

Kavitha M

  • NA
  • 21
  • 6.4k

Mail from HTML page using PHP

May 6 2015 8:07 AM
Hi all,
 
I have contact form in html page. I have 3 fields NAme,Message,Email. I want to send these data to another email. I try this with PHP as follows. It shows success message. But i am not receiving any mail. Can anyone help me to solve this.
 
script:
<script type="text/javascript">
$(document).ready(function(){
$('#submit').click(function(){
var name=$('#name').val();
var email=$('#email').val();
var message=$('#message').val();
var vardata = 'name=' + name + '&email=' + email + '&message=' + message;
console.log(vardata);
alert(vardata);
$.ajax({
type: "POST",
url: 'send_mail.php',
data: vardata,
success: function () {
alert(vardata);
alert("success");
}
});
});
});
</script>
Form:
<form action="send_mail.php" class="contact-form" method="post">
<div class="row">
<div class="form-group col-sm-6" style="color:#333333;">
<label for="name">Name</label>
<input class="form-control" id="name" name="name" onblur="if(this.value == '') this.value='Name'" onfocus="if(this.value == 'Name') this.value=''" type="text" value="Name">
<div class="error" id="err-name">Please enter name</div>
</div>
<div class="form-group col-sm-6" style="color:#333333;">
<label for="email">E-mail</label>
<input class="form-control" id="email" name="email" type="text" onfocus="if(this.value == 'E-mail') this.value='';" onblur="if(this.value == '') this.value='E-mail';" value="E-mail">
<div class="error" id="err-emailvld">E-mail is not a valid format</div>
</div>
</div>
<div class="row">
<div class="form-group col-md-12" style="color:#333333;">
<label for="message">Message</label>
<textarea class="form-control" id="message" name="message" onblur="if(this.value == '') this.value='Message'" onfocus="if(this.value == 'Message') this.value=''">Message</textarea>
<div class="error" id="err-message">Please enter message</div>
</div>
</div>
<div class="row spacer30"></div>
<div class="row">
<div class="col-md-12 text-center" style="color:#333333;">
<div id="ajaxsuccess">E-mail was successfully sent.</div>
<div class="error" id="err-form">There was a problem validating the form please check!</div>
<div class="error" id="err-timedout">The connection to the server timed out!</div>
<div class="error" id="err-state"></div>
<!--<button type="submit" class="btn btn-primary" id="send" onclick="document.getElementById('ajax-form').submit()">Submit</button>-->
<input type="button" id="submit" name="submit" value="Submit" class="btn btn-primary" />
<!--<button onclick="sendMail(); return false" class="btn btn-primary">Submit</button>-->
</div>
</div>
</form>
php :
<?php      $tomail='[email protected]'; 
$name=$_POST['name']; 
$email=$_POST['email']; 
$message=$_POST['message'];   
$headers = "From: $name\n";
$headers .= "Reply-To: $email_address";   
mail($tomail,"Contact Form-Enquiry",$message,$headers); ?>
 
 
 
Thanks in advance 

Answers (3)