Perhaps the question is stupid, but I'm still a novice, so I can not handle the second day. It is impossible to simultaneously receive mail and data on the form and text data from the block.
The main problem begins in the JS file with the line $ .post ('Post_Constructor.php' ...
If I delete '& item_price =' + $ ('# price'). Text ()
- Come to email data on the form!
And if I delete $ ('# contruct-from'). SerializeArray ()
- Comes to the email text content
<span id="price">900</span>
- Comes to the email text content
If nothing is deleted, then the browser inspector will show this:
item_price: 900 [object Object], [object Object], [object Object]
... and the form will be given the number 900 I need and the string of "objects".
As far as I know, the matter is not with the handler, but in the wrong data transfer.
HTML
<span id="price">900</span> <form id="contruct-from"> <input name="namecontr"> <input name="telcontr"> <input name="emailcontr"> <button form="contruct-from" type="submit">ОТПРАВИТЬ</button> </form> Js
$('.btn-contruct').click(function(){ if($("#contruct-from")[0].checkValidity()) { $.post('Post_Constructor.php', '&item_price=' + $('#price').text() + $('#contruct-from').serializeArray(), function(data) { }); console.log('ok'); return false; } }); PHP handler
<?php session_start(); new post_contact($_POST); class post_contact { public function __construct($post_data) { $this->send_contact_form($post_data); } function send_contact_form($post_data) { $headers = "MIME-Version: 1.0" . PHP_EOL . "Content-Type: text/html; charset=utf-8" . PHP_EOL . 'From: test@email.com <test@email.com>' . PHP_EOL; $message = '<p>'.$_POST['namecontr'].'</p>'; $message .= '<p>'.$_POST['telcontr'].'</p>'; $message .= '<p>'.$_POST['emailcontr'].'</p>'; $message .= '<p>'.$_POST['item_price'].'</p>'; mail('test@email.com', 'Помогите пожалуйста', $message, $headers ); } }