after submitting a form to email i get 2 email instead 1 how can i fix it? I need that only 1 letter come to email
js:
app.controller('threeCtrl',function($scope){
$("#subBusinessOne").click(function() {
var url = "businessFormOne.php";
$.ajax({
type: "POST",
url: url,
data: $("form#businessFormOne").serialize(),
success: function(data)
{
var name = $("input[name=name]").val("");
var rel= $("input[name=phone]").val("");
}
});
return false; // avoid to execute the actual submit of the form.
});
});
php:
<?php
$ToEmail = 'myemail.com';
$EmailSubject = 'Охрана бизнес-обьектов';
$mailheader = "From: ".$_POST["email"]."\r\n";
$MESSAGE_BODY = "Имя: ".$_POST["name"]."";
$MESSAGE_BODY .= "Телефон: ".$_POST["phone"]."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
I guess that #subBusinessOne
is a form submit button. You're sending an AJAX request and then submitting the form again as a normal HTTP request.
Instead of detecting button click event, you should check if the form has been submitted, then prevent default action and send the AJAX request. Your JS code would then look like this:
app.controller('threeCtrl',function($scope){
$("#businessFormOne").submit(function(e) {
e.preventDefault(); // this is to avoid the actual submit
var url = "businessFormOne.php";
$.ajax({
type: "POST",
url: url,
data: $("form#businessFormOne").serialize(),
success: function(data)
{
var name = $("input[name=name]").val("");
var rel= $("input[name=phone]").val("");
}
});
});
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments