There is a standard form :
<form> <input type="text" name="name" id="name"> <input type="text" name="email" id="email"> </form> ajax request :
var str = form.serialize(); $.ajax({ url: 'contacts.php', type: 'post', data: str }).done(function(msg) { if (msg === "OK") { console.log('сообщение отправлено'); $(".res").html(res); } else { $(".res").html(msg); } }).always(function() { ... }); }); And there is contacts.php itself:
<?php define("CONTACT_FORM", 'myEmail@gmail.com'); $subject = 'Заявка'; $name = stripslashes($_POST['name']); $phone = stripslashes($_POST['phone']); $email = stripslashes($_POST['email']); $msg = stripslashes($_POST['msg']); $error = ''; $message = ' <html> <head> <title>Заявка</title> <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> </head> <body> <p>Имя : '.$name.'</p> <p>Email : '.$email.'</p> <p>Phone : '.$phone.'</p> <p>Message : '.$msg.'</p> </body> </html>'; $mail = mail(CONTACT_FORM, $subject, $message, "MIME-Version: 1.0\r\n" ."From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."Content-type: text/html; charset=UTF-8\r\n" ."X-Mailer: PHP/" . phpversion()); if($mail){ echo "OK"; } ?> where 'myEmail@gmail.com' is the address where letters should come.
No errors are written that everything is perfectly sent (js works "OK" from php comes in any case).
If myEmail@gmail.com entered in the form field, then letters arrive, and if Vasya@mail.ru (or any other mailing address) is entered in the form field - letters simply do not come.
Question: why when filling in the form and sending, the letter comes to the mail only if the email address in the form ( <input type="text" name="email" id="email" > ) matches define("CONTACT_FORM", 'myEmail@gmail.com'); ? How can I fix .php?
str. And what do the logs say? - Alexstr. No errors there is no writes that everything is perfectly sent. Letters frommyEmail@gmail.comtomyEmail@gmail.comcome, and fromVasya@mail.rutomyEmail@gmail.comsimply do not come. - HamSter."From: ".$name." <".$email.">\r\n"with."From: ".$name." <".CONTACT_FORM.">\r\n"and you will happiness. - Visman