HTML:

<form action="send.php" method="post"> <!-- Hidden Required Fields --> <input type="hidden" name="project_name" value="uzinouzi.com"> <input type="hidden" name="admin_email" value="uzi.no.uzi.web@gmail.com"> <input type="hidden" name="form_subject" value="Заказ"> <!-- END Hidden Required Fields --> <input type="text" placeholder="Имя" name="name" required> <input type="text" placeholder="E-mail" name="mail" required> <textarea name="message" id="textarea" placeholder="Сообщение" required></textarea> <button id='sendApp'>Отправить</button> </form> 

Js:

 $(document).ready(function() { //E-mail Ajax Send $("form").submit(function() { //Change var th = $(this); $.ajax({ type: "POST", url: "send.php", //Change data: th.serialize() }).done(function() { alert("Thank you!"); setTimeout(function() { // Done Functions th.trigger("reset"); }, 1000); }); return false; }); }); 

PHP:

 <?php $method = $_SERVER['REQUEST_METHOD']; //Script Foreach $c = true; if ( $method === 'POST' ) { $project_name = trim($_POST["project_name"]); $admin_email = trim($_POST["admin_email"]); $form_subject = trim($_POST["form_subject"]); foreach ( $_POST as $key => $value ) { if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) { $message .= " " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . " <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td> <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td> </tr> "; } } } else if ( $method === 'GET' ) { $project_name = trim($_GET["project_name"]); $admin_email = trim($_GET["admin_email"]); $form_subject = trim($_GET["form_subject"]); foreach ( $_GET as $key => $value ) { if ( $value != "" && $key != "project_name" && $key != "admin_email" && $key != "form_subject" ) { $message .= " " . ( ($c = !$c) ? '<tr>':'<tr style="background-color: #f8f8f8;">' ) . " <td style='padding: 10px; border: #e9e9e9 1px solid;'><b>$key</b></td> <td style='padding: 10px; border: #e9e9e9 1px solid;'>$value</td> </tr> "; } } } $message = "<table style='width: 100%;'>$message</table>"; function adopt($text) { return '=?UTF-8?B?'.Base64_encode($text).'?='; } $headers = "MIME-Version: 1.0" . PHP_EOL . "Content-Type: text/html; charset=utf-8" . PHP_EOL . 'From: '.adopt($project_name).' <'.$admin_email.'>' . PHP_EOL . 'Reply-To: '.$admin_email.'' . PHP_EOL; mail($admin_email, adopt($form_subject), $message, $headers ); ?> 

Put everything on a local host, through the Open Server.

 alert("Thank you!"); 

After pressing the button, i.e. everything went well, but there is nothing in the mail. What could be the problem?

  • I think your mail is not configured on localhost, in my opinion in the Open Server you can see the mail that supposedly should have gone. - Yaroslav Molchan
  • [Fri Dec 29 12: 06: 47.013451 2017] [ssl: warn] [pid 9156: tid 200] AH01909: miki.loc: 443: 0 server certificate [Fri Dec 29 12: 06: 47.014441 2017] [ssl: warn] [pid 9156: tid 200] AH01909: default: 443: 0 server certificate [Fri Dec 29 12: 06: 47.042532 2017] [mpm_winnt: notice] [pid 9156: tid 200] AH00354: Child: Starting 32 worker threads. Apache debugging, miki.loc is the domain I did. - uzi_no_uzi
  • 2
    if the mail is not configured, then you need to look in `OpenServer \ userdata \ temp \ email` - Alexey Shimansky
  • I set up the mail, but in the logs it writes to me that it is sent to the wrong email that I need (I accidentally when I first sent the wrong email to the input I entered, it seems to be saved somewhere), how can I change it? In the input I changed. - uzi_no_uzi
  • prntscr.com/htq3zw - Here are the logs, I fixed the problem with the wrong email-om prntscr.com/htq4e7 - Here are the mail settings. - uzi_no_uzi

0