title: Invalid Address: SMTP Error: Could not connect to SMTP host
body: <p>I am trying to use gmail smtp server to send emails via php mailer from a php form. i have opened the 465 port from windows firewall but the port doesn't appear in the cmd output when i type </p>
  
  <blockquote>
    <p>netstat -an</p>
  </blockquote>
  
  <p>command.the error that appears in the php page is:
  <strong>Invalid address: SMTP Error: Could not connect to SMTP host.</strong>
  there is no exact solution for my issue in the result of my searchs. my code is:</p>
  
  <pre><code>&lt;?php
   require_once('PHPMailer_v5.1/class.phpmailer.php');
   define('GUSER', 'from@gmail.com'); // GMail username
  define('GPWD', 'password'); // GMail password
  function smtpmailer($to, $from, $from_name, $subject, $body) { 
      global $error;
      $mail = new PHPMailer();  // create a new object
      $mail-&gt;IsSMTP(); // enable SMTP
      $mail-&gt;SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
      $mail-&gt;SMTPAuth = true;  // authentication enabled
      $mail-&gt;SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
      $mail-&gt;Host = 'smtp.gmail.com';
      $mail-&gt;Port = 465; 
      $mail-&gt;Username = GUSER;  
      $mail-&gt;Password = GPWD;           
      $mail-&gt;SetFrom($from, $from_name);
      $mail-&gt;Subject = $subject;
      $mail-&gt;Body = $body;
      $mail-&gt;AddAddress($to);
      if(!$mail-&gt;Send()) {
          $error = 'Mail error: '.$mail-&gt;ErrorInfo; 
          return false;
      } else {
          $error = 'Message sent!';
          return true;
      }}
      if(smtpmailer('from@gmail.com', 'to@gmail.com', 'name', 'test mail message', 'Hello World!')){
          echo "sent";
      if (!empty($error)) echo $error;}
  
    ?&gt;
  </code></pre>
  
  <p>note: i am using localhost for my site</p>