A
A
Alexey102018-02-09 20:59:32
PHP
Alexey10, 2018-02-09 20:59:32

Sending ajax forms to mail, (if there is more than one form) how?

Guys, hello everyone
Such a question:
I use sending forms via ajax to the mail. Everything sends well.
But there is not one form on the page, but as many as 10 (that is, 10 form tags). I made 10 php files and ajax codes.
Everything works great. But the customer asked for the php file to be one. How do I merge 10 php files into one? (php I don't know, so please help). And most importantly, you need to take into account that the title is different for each form should come.
Thank you all for your help))
ajax code:
$(document).ready(function () {
$("#form2").submit(function () {
$.ajax({
type: "POST"
, url: "mail2. php"
, data: $(this).serialize()
}).done(function () {
$(this).find("input").val("");
$("#form2").trigger("reset");
$.fancybox.open($( "#pop"));
setTimeout(function () {
$.fancybox.close();
}, 1500);
});
return false;
});
});

PHP code:
$recipient = "";
$sitename = "";

$tel = trim($_POST["tel"]);
$message = "Phone: $tel\n";

$pagetitle = "New ticket from the form. Website \"$sitename\"";
mail($recipient, $pagetitle, $message, " Content-type: text/plain; charset=\"utf-8\"\n From: $recipient");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
I'm Yoda, 2018-02-09
@Anadi

In the "mail.php" form handler, you check what data came from which form, based on the received data, you form the response header. There is nothing complicated in this!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question