Faced a problem. The form does not send data. An empty letter arrives in the mail. Only header and sender. Wordpress site

Here is the code:

<div class="form_back"> <p class="text"><h1>Contact to us</h></p> <?php $to = "blabla@mail.com"; $subject = 'New message for you'; $message = $_POST['mess']; $headers = 'From: info@mail.com'; mail($to, $subject, $message, $headers); ?> <form action="" action="<?php echo get_permalink(); ?> " method="post"> <ol style="list-style-type: none;"> <div><h5>Your name</h5></div> <li><input type="text" name="name" required="required"/></li> <div><h5>Your email</h5></div> <li><input type="text" name="email" required="required"/></li> <div><h5>Message</h5></div> <li><textarea name="mess"></textarea></li> <li><h4><input type="submit" value="Send message" name="submit"></h4></li> </ol> </form> </div> 

  • Just checked, everything works! - Ihor Tkachuk
  • And what about $_POST['mess'] , did you check? Maybe there is empty ... - Roman Grinyov

2 answers 2

If the site is on a localhost, the message can not come. It is better to use wp_mail() instead of just mail() , since you have a site on vp.

    1. Use not php mail , but wp_mail here is the link to the documentation or, if you don’t understand bourgeois.
    2. Most likely your letter comes to spam in any case that is in the $_POST array.
    3. If you don’t really understand php mail and smtp , use plug-ins for example Contact Form 7 to create sending and processing forms and WP Mail SMTP to configure SMTP.
    • @Alex ochepyatatsya yes $ _POST - Sergalas