title: Warning: trim() expects parameter 1 to be string, array given in wp-includes/class-phpmailer.php on line 973
body: <p>I am trying to send an email from my wordpress website using the function wp_mail and I am getting this error: </p>
  
  <pre><code>Warning: trim() expects parameter 1 to be string, array given in /var/www/html/wp-includes/class-phpmailer.php on line 973 0
  </code></pre>
  
  <p>I don't really understand why I am getting it. </p>
  
  <p>This is my current code: </p>
  
  <pre><code>// Contact form  Ajax 
  
  add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form'); 
  
  function submit_contact_form(){
  
      if(isset($_POST['email'])) {
  
          $email = $_POST['email'];       
          $email_to = "info@yyy.com";
  
          $host = "ssl://smtp.gmail.com:465";
          $username = 'myEmail@gmail.uk';
          $password = 'mypassword';
  
          $email_subject = "You have a new email from $email via yyy.com website";
          $message = $_POST['text']; 
  
          $headers = array ('From' =&gt; $email, 'To' =&gt; $email_to,'Subject' =&gt; $email_subject);
          /*$smtp = Mail::factory('smtp',
            array ('host' =&gt; $host,
              'auth' =&gt; true,
              'username' =&gt; $username,
              'password' =&gt; $password));*/
  
          //$mail = $smtp-&gt;send($email_to, $headers, $message);
  
          wp_mail( $email_to, $headers, $message );
  
          /*if (PEAR::isError($mail)) {
            echo($mail-&gt;getMessage());
          } else {
            echo("Message successfully sent!\n");
          }*/
      }
  }
  
  
  
  error_reporting(E_ALL);
  ini_set("display_errors", 1);
  </code></pre>