title: contact email form wont send with smtp
body: <p>I have created a contact form that is to be sent to a gmail address for testing purposes.
  However, after setting up sentmail for SMTP, the form I have created will not send.</p>
  <p>I am now getting the message: Apache/2.4.51 (Win64) OpenSSL/1.1.1l PHP/7.4.26 Server at localhost Port 80.</p>
  <p>I used the following link to set up the php.ini and sendmail.ini: <a href="https://websistent.com/using-sendmail-on-windows/" rel="nofollow noreferrer">https://websistent.com/using-sendmail-on-windows/</a></p>
  <p>So the php.ini and sendmail.ini files have been set up and the following code is being used</p>
  <pre><code>        &lt;form action=&quot;forms/contact.php&quot; method=&quot;post&quot; autocomplete=&quot;on&quot;&gt;
            &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-lg form-group&quot;&gt;
                &lt;label for=&quot;enter-name&quot;&gt;Name:&lt;/label&gt;
                &lt;input type=&quot;text&quot; id=&quot;enter-name&quot; name=&quot;visitor_name&quot; class=&quot;form-control&quot;  placeholder=&quot;Your Name&quot; pattern=[A-Z\sa-z]{3,20} required&gt;
              &lt;/div&gt;
              &lt;div class=&quot;col-lg form-group &quot;&gt;
                &lt;label for=&quot;enter-email&quot;&gt;Email:&lt;/label&gt;
                &lt;input type=&quot;email&quot; id=&quot;enter-email&quot; name=&quot;visitor_email&quot; class=&quot;form-control&quot;  placeholder=&quot;Your Email&quot; required&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;form-group &quot;&gt;
              &lt;label for=&quot;enter-selection&quot; class=&quot;pt-3 topics pb-2&quot;&gt;Reason for contacting:&lt;/label&gt;&lt;br /&gt;
  
              &lt;select id=&quot;enter-selection&quot; name=&quot;visitor_topic&quot; required&gt;
            &lt;option value=&quot;&quot; disabled selected&gt;Select a Topic&lt;/option&gt;                  
  
                &lt;option value=&quot;experience&quot;&gt;Restaurant Experience&lt;/option&gt;
                &lt;option value=&quot;to-go&quot;&gt;To-go Experience&lt;/option&gt;
                &lt;option value=&quot;queries&quot;&gt;Questions or Suggestions&lt;/option&gt;
                &lt;option value=&quot;technical support&quot;&gt;Technical Help&lt;/option&gt;
                &lt;option value=&quot;other&quot;&gt;Other&lt;/option&gt;
  
             &lt;/select&gt;
            &lt;/div&gt;
  
         &lt;div class=&quot;form-group&quot;&gt;
         &lt;label for=&quot;enter-message&quot;&gt;Message:&lt;/label&gt;
          &lt;textarea class=&quot;form-control&quot; id=&quot;enter-message&quot; name=&quot;visitor_message&quot; placeholder=&quot;Contact us...&quot;&gt;&lt;/textarea&gt;
          &lt;div class=&quot;validate&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
            &lt;div class=&quot;text-center pb-3&quot;&gt;&lt;button type=&quot;submit&quot;&gt;Send Message&lt;/button&gt;&lt;/div&gt;
          &lt;/form&gt;&lt;!--End of form--&gt;
  
  &lt;?php
  //the filter_var()function is used to validate or sanitize all types of user input.
  //htmlspecialchars() function encodes all special HTML characters in the visitor message sent 
  if($_POST) {
      $visitor_name = &quot;&quot;;
      $visitor_email = &quot;&quot;;
      $visitor_topic = &quot;&quot;;
      $visitor_message = &quot;&quot;;
      $email_body = &quot;&lt;div&gt;&quot;;
        
      if(isset($_POST['visitor_name'])) {
          $visitor_name = filter_var($_POST['visitor_name'], FILTER_SANITIZE_STRING);
          $email_body .= &quot;&lt;div&gt;
                             &lt;label&gt;&lt;b&gt;Visitor Name:&lt;/b&gt;&lt;/label&gt;&amp;nbsp;&lt;span&gt;&quot;.$visitor_name.&quot;&lt;/span&gt;
                          &lt;/div&gt;&quot;;
      }
   
      if(isset($_POST['visitor_email'])) {
          $visitor_email = str_replace(array(&quot;\r&quot;, &quot;\n&quot;, &quot;%0a&quot;, &quot;%0d&quot;), '', $_POST['visitor_email']);
          $visitor_email = filter_var($visitor_email, FILTER_VALIDATE_EMAIL);
          $email_body .= &quot;&lt;div&gt;
                             &lt;label&gt;&lt;b&gt;Visitor Email:&lt;/b&gt;&lt;/label&gt;&amp;nbsp;&lt;span&gt;&quot;.$visitor_email.&quot;&lt;/span&gt;
                          &lt;/div&gt;&quot;;
      }
        
      if(isset($_POST['visitor_topic'])) {
          $visitor_topic = filter_var($_POST['visitor_topic'], FILTER_SANITIZE_STRING);
          $email_body .= &quot;&lt;div&gt;
                             &lt;label&gt;&lt;b&gt;Reason For Contacting Us:&lt;/b&gt;&lt;/label&gt;&amp;nbsp;&lt;span&gt;&quot;.$visitor_topic.&quot;&lt;/span&gt;
                          &lt;/div&gt;&quot;;
      }
        
     
      if(isset($_POST['visitor_message'])) {
          $visitor_message = htmlspecialchars($_POST['visitor_message']);
          $email_body .= &quot;&lt;div&gt;
                             &lt;label&gt;&lt;b&gt;Visitor Message:&lt;/b&gt;&lt;/label&gt;
                             &lt;div&gt;&quot;.$visitor_message.&quot;&lt;/div&gt;
                          &lt;/div&gt;&quot;;
      }
        
      if($visitor_topic == &quot;experience&quot;) {
          $recipient = &quot;digi@gmail.com&quot;;
      }
      else if($visitor_topic == &quot;to-go&quot;) {
          $recipient = &quot;digi@gmail.com&quot;;
      }
       else if($visitor_topic == &quot;queries&quot;) {
          $recipient = &quot;digi@gmail.com&quot;;
      }
      else if($visitor_topic == &quot;technical support&quot;) {
          $recipient = &quot;digi@gmail.com&quot;;
      }
      else {
          $recipient = &quot;digi@gmail.com&quot;;
      }
        
      $email_body .= &quot;&lt;/div&gt;&quot;;
   
      $headers  = 'MIME-Version: 1.0' . &quot;\r\n&quot;
      .'Content-type: text/html; charset=utf-8' . &quot;\r\n&quot;
      .'From: ' . $visitor_email . &quot;\r\n&quot;;
        
      if(mail($recipient, $email_body, $headers)) {
          echo &quot;&lt;p&gt;Thank you for contacting us, $visitor_name. You will get a reply within 24 hours.&lt;/p&gt;&quot;;
      } else {
          echo '&lt;p&gt;We are sorry but the email did not send&lt;/p&gt;';
      }
        
  } else {
      echo '&lt;p&gt;Something went wrong&lt;/p&gt;';
  }
  ?&gt;
  </code></pre>
  <p>Any help would be most appreciated as have tried for ages!</p>