title: PHP contact-form email error
body: <p>I have this email form that I want on my website, I tried it before and it worked perfectly, but now it suddenly stopped working and won't send a mail for some reason... I have not changed anything in the code and don't know how to fix it... </p>
  
  <p>Here are the codes used:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;?php
  if(!isset($_POST['submit']))
  {
   //This page should not be accessed directly. Need to submit the form.
   echo "fel; du måste ha skickat!";
  }
  $name = $_POST['name'];
  $visitor_email = $_POST['email'];
  $message = $_POST['message'];
  
  //Validate first
  if(empty($name)||empty($visitor_email)) 
  {
      echo "Namn och mailaddress är obligatoriskt!";
      exit;
  }
  
  if(IsInjected($visitor_email))
  {
      echo "Fel mailaddress!";
      exit;
  }
  
  $email_from = 'info@beni.se';//&lt;== update the email address
  $email_subject = "Nytt meddelande";
  $email_body = "Nytt meddelande från $name.\n \n".
      "Han/hon skrev:\n \n $message\n \n $visitor_email \n \n \n".
      
  $to = "info@beni.se";//&lt;== update the email address
  $headers = "From: $visitor_email \r\n";
  $headers .= "Reply-To: $visitor_email \r\n";
  //Send the email!
  mail($to,$email_subject,$email_body,$headers);
  //done. redirect to thank-you page.
  header('Location: thank-you.html');
  
  ?&gt; </code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!-- =====================START contact form===================== --&gt;
   &lt;div class="row scroll wow animated flash" id="contact-form" style="height: 100%; animation-delay: 0.5s;"&gt;
    &lt;div class="col-md-4 col-sm-12 panel panel-default features email-block" style="padding-left: 0; padding-right: 0; border-radius: 15px; margin: 0;"&gt;
     &lt;div class="panel-heading" style="border-top-left-radius: 15px; border-top-right-radius: 15px;"&gt;
      &lt;h1 style="margin-top: 10px;"&gt;Anlita oss nu!&lt;/h1&gt;
     &lt;/div&gt;&lt;!-- //.panel-heading --&gt;
     &lt;div class="panel-body" style="padding-right: 0; padding-bottom: 0; padding-left: 0;"&gt;
      &lt;form method="post" name="myemailform" action="form-to-email.php"&gt;
       &lt;p&gt;
        &lt;label for='name'&gt;Fullständiga namn: &lt;/label&gt;&lt;br&gt;
        &lt;input type="text" placeholder="John Svensson" style="width: 300px; border-radius: 5px;" name="name"&gt;
       &lt;/p&gt;
       &lt;p&gt;
        &lt;label for='email'&gt;Mailaddress:&lt;/label&gt;&lt;br&gt;
        &lt;input type="text" placeholder="exempel@domän.se" style="width: 300px; border-radius: 5px;" name="email"&gt;
       &lt;/p&gt;
       &lt;p&gt;
        &lt;label for='message'&gt;Meddelande:&lt;/label&gt; &lt;br&gt;
        &lt;textarea name="message" placeholder="Skriv ett meddelande..." style="width: 300px; height: 125px; border-radius: 5px; resize: none;"&gt;&lt;/textarea&gt;
       &lt;/p&gt;
       &lt;input class="btn btn-warning btn-block" style="border-radius: 0px; border-bottom-right-radius: 15px; border-bottom-left-radius: 15px;" type="submit" name='submit' value="Skicka"&gt;
      &lt;/form&gt;
      &lt;script language="JavaScript"&gt;
      // Code for validating the form
      // Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
      // for details
      var frmvalidator  = new Validator("myemailform");
      frmvalidator.addValidation("name","req","Var god och skriv in ditt namn.");
      frmvalidator.addValidation("email","req","Var god och skriv in din mailaddress.");
      frmvalidator.addValidation("email","email","Var god och skriv in en giltig mailaddress.");
      &lt;/script&gt;
     &lt;/div&gt;&lt;!-- //.col-md-4 panel-body --&gt;
    &lt;/div&gt;&lt;!-- //.panel --&gt;
   &lt;/div&gt;&lt;!-- //.row --&gt;
  &lt;!-- =====================END contact form===================== --&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I tried using this before the <code>mail($to,$email_subject,$email_body,$headers);</code>:</p>
  
  <pre><code>error_reporting(-1);
  ini_set('display_errors', 'On');
  set_error_handler("var_dump");
  </code></pre>
  
  <p>When I use that, I get:</p>
  
  <pre><code>    int(2)
  string(164) "mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()"
  string(59) "D:\HostingSpaces\rtruintm\beni.se\wwwroot\form-to-email.php"
  int(36)
  array(12) {
    ["_GET"]=&gt;
    array(0) {
    }
    ["_POST"]=&gt;
    array(4) {
      ["name"]=&gt;
      string(10) "Bence Papp"
      ["email"]=&gt;
      string(16) "test@hotmail.com"
      ["message"]=&gt;
      string(6) "meh :c"
      ["submit"]=&gt;
      string(6) "Skicka"
    }
    ["_COOKIE"]=&gt;
    array(0) {
    }
    ["_FILES"]=&gt;
    array(0) {
    }
    ["name"]=&gt;
    string(10) "Bence Papp"
    ["visitor_email"]=&gt;
    string(16) "test@hotmail.com"
    ["message"]=&gt;
    string(6) "meh :c"
    ["email_from"]=&gt;
    string(12) "info@beni.se"
    ["email_subject"]=&gt;
    string(15) "Nytt meddelande"
    ["email_body"]=&gt;
    string(98) "Nytt meddelande från Bence Papp.
  
  Han/hon skrev:
  
   meh :c
  
   test@hotmail.com 
  
  
  info@beni.se"
    ["to"]=&gt;
    string(12) "info@beni.se"
    ["headers"]=&gt;
    string(54) "From: test@hotmail.com 
  Reply-To: test@hotmail.com 
  "
  }
  </code></pre>