I use phpmailer

html:

<form action="block/mail.php" method="post"> <div class="inputs"> <ul> <li>Фамилия:<br><input type="text" id="last_name" name="last_name"></li> <li">Имя:<br><input type="text" id="first_name"></li> <li>Телефон:<br><input type="text" id="phone" name="phone"></li> <li">E-mail:<br><input type="text" id="email" name="email"></li> <button type="submit">Отправить</button> </ul> </div> </form> 

php:

 <?php require 'class.phpmailer.php'; $lname = $_POST['last_name']; $fname = $_POST['first_name']; $phone = $_POST['phone']; $email = $_POST['email']; $mail = new PHPMailer; $mail->From = 'test@test.com'; $mail->FromName = 'Testname'; $mail->AddAddress('test2@test.com'); $mail->WordWrap = 50; $mail->IsHTML(true); $mail->Body = "Name: $lname"; $mail->Send(); ?> 
  • Form data is not sent or mail? If the mailing, then how did you define it? Error displays? Tested on a real hosting or local? If the latter, then checked the appropriate folder where the letters should be stored after the emulation of sending? - Deonis
  • And sent to localhost, I suppose? And all on Windows? Well, you need to configure it properly. - zhenyab
  • On the local, there are no errors, the folder is empty. If you just execute a php letter comes - moserevg
  • Soon I will start on this type of questions to write a lot of bad words and minuses to put. Where check (hosting? Lokalka?) Sendmail is configured? gives errors? what kind? Do not show us that you wrote off the example, but it does not work. Tell us what you tried to do and what happened. I think this is how you get answers faster. - binliz
  • There are no errors at all, everything is configured and works, but only does not send with the button - moserevg

1 answer 1

Why is the method attribute not specified in the form? Well you probably check - did the data come or not? By default (without specifying it), it is sent from you GET method, and you accept as POST


Also, I checked your code by making one single change: method = "post" . Everything is working.

  • Thanks to everyone, the problem is in action = "block / mail.php" How to specify the address correctly? - moserevg
  • @moserevg, do you mean that the path indicated is not true? Or what address is it? - Deonis
  • I'm already confused. I have a form in a pop-up block, which is initially display = none and appears through js. For some reason, because of this, the letter is not sent. If you do display = block, then everything is fine - moserevg
  • Do you have the "block" folder in the root of the site? If yes, then try and specify the path from the root. Ie in your case, you need to add a slash to the beginning of the path: action = "/ block / mail.php" - Deonis
  • Thanks again. Decided to redo the popup - moserevg pm