title: Setting SMTP details for php mail () function
body: <p>I have been looking for an answer and tried many things to this problem.</p>
  
  <p>My script works fine on my webhost but when moving it to an other dedicated server the mail never gets delivered. Now i need to set the SMTP server but don't get it right.</p>
  
  <p>Using Gmail apps btw. This is how the code looks like.</p>
  
  <pre><code>&lt;?php
  
  if(!$_POST) exit;
  
  $email = $_POST['email'];
  
  
  //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
  if(!eregi("@",$email )){
      $error.="Invalid email address entered";
      $errors=1;
  }
  if($errors==1) echo $error;
  else{
      $values = array ('name','email','telephone','message');
      $required = array('name','email','telephone','message');
  
      $your_email = "xxx@example.com";
      $email_subject = "New Messag: ".$_POST['subject'];
      $email_content = "New message:\n";
  
      foreach($values as $key =&gt; $value){
        if(in_array($value,$required)){
          if ($key != 'subject' &amp;&amp; $key != 'telephone') {
            if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
          }
          $email_content .= $value.': '.$_POST[$value]."\n";
        }
      }
  
      if(@mail($your_email,$email_subject,$email_content)) {
          echo 'Message sent!'; 
      } else {
          echo 'ERROR!';
      }
  }
  
  $mail-&gt;Mailer = "smtp";  
  $mail-&gt;Host = "ssl://smtp.gmail.com";  
  $mail-&gt;Port = 465;  
  $mail-&gt;SMTPAuth = true; // turn on SMTP authentication  
  $mail-&gt;Username = "user@gmail.com"; // SMTP username  
  $mail-&gt;Password = "password"; // SMTP password 
  
  ?&gt;
  </code></pre>
  
  <p>So how do i set the SMTP settings right?</p>