我继承了代码,现在我遇到了无法检测到的问题。当我填写表格时,我会收到2封电子邮件而不是1封。所以,如果有人可以帮助我并告诉我原因。 我的代码在这里: HTML:
<div class="container text-center forma-kontakt">
<form class="form-inline" id="upitForma" method="POST">
<div class="form-group xx">
<label class="sr-only" for="email2">Ime:</label>
<input type="email2" class="form-control" id="upitIme" placeholder="Unesite Vase ime">
<br>
<br>
</div>
<div class="form-group">
<label class="sr-only" for="ime2">Email:</label>
<input type="text" class="form-control" id="upitEmail" placeholder="Unesite Vas email">
<br>
<br>
</div>
<br>
<div class="form-group">
<label class="sr-only" for="ime2">Adresa Vašeg web-sajta:</label>
<input type="text" class="form-control" id="upitSajt" placeholder="Vaš web-sajt (opciono):">
<br>
<br>
</div>
<div class="form-group text-center" style="display:block">
<label for="message" class="col-sm-12 control-label text-center">Poruka</label>
<div class="col-sm-12">
<textarea class="form-control" rows="4" name="message2" style="height:260px; width:600px"
id="upitMsg"></textarea>
<br>
<br>
</div>
</div>
<input type="submit" id="upitBtn" class="btn btn-primary center-block" style="margin-top:20px; width:100px" value="Pošalji poruku">
</input>
</form>
</div>
PHP:
<?php
class Upit extends Controller {
public function index() {
$this->view("upit/index", []);
}
public function upit() {
if (isset($_POST['ime']) & isset($_POST['eMail']) & isset($_POST['poruka'])) {
$ime = $_POST['ime'];
$mail = $_POST['eMail'];
$poruka = $_POST['poruka'];
} else
return 0;
if (isset($_POST['listaUsluga']))
$listaUsluga = $_POST['listaUsluga'];
else
$listaUsluga = '';
if (isset($_POST['sajt']))
$sajt = $_POST['sajt'];
else
$sajt = '';
echo 1;
$to = 'example@mail.com';
$subject = 'Upit kontakt';
$message = "Novi kontakt od osobe: $ime (eMail: $mail ) \r\nPoruka glasi: \r\n $poruka \r\n\r\n Selektovana lista usluga: $listaUsluga\r\n\r\n $sajt\r\n\r\n !!! Ovo je automatska poruka, ne odgovarati na dugme REPLAY !!!";
//$headers = 'From: example@mail.com' . "\r\n" .
//'Reply-To: From: example@mail.com' . "\r\n" .
//'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $header);
}
}
?>
JS:
$('#upitBtn').on("click", function(e) {
e.preventDefault();
var myForm = $('#dugme');
var anyBoxChecked = false;
var i;
var txt = "";
var ime = $('#upitIme').val();
var eMail = $('#upitEmail').val();
var poruka = $('#upitMsg').val();
var sajt = $('#upitSajt').val();
$('#dugme input:checked').each(function(e) {
//if($(this).is(":checked")) {
anyBoxChecked = true;
txt += " " + $(this).val();
//}
});
var $myForm = $('#upitForma');
if (!$myForm[0].checkValidity())
$myForm.find(':submit').click();
else
e.preventDefault();
var eMail = $('#upitEmail').val().trim();
/*alert(eMail);
alert(txt);
alert(ime);
alert(poruka);*/
$.ajax({
async:false,
type: "POST",
url: "/upit/upit/",
dataType: 'text',
//data: {eMail:eMail, listaUsluga:txt, ime:ime, poruka:poruka, sajt:sajt},
cache: false
})
.done(function(rez) {
if (rez=="0") {
$('#upitEmail').css({ "border": '#FF0000 1px solid'});
$('#upitEmail').val('');
$('#upitEmail').attr("placeholder", "Unesite ispravan mail!");
} else {
$('#upitEmail').val('');//TODO obrisati values i svih ostalih polja
$('#modalBoxUspehUpit').trigger("click");
}
})
.fail(function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
console.log(ajaxOptions);
console.log(thrownError);
});
return false;
});
我不知道这是一个正确的问题,但我被困住了,不知道哪里出错了。所以欢迎所有的意见和建议。