title: can't use smtp.gmail using phpmailer
body: <p>I know this kind of question asked so many times in <a href="http://stackoverflow.com">stackoverflow</a>, but I looked at most of them and the problem still remains.
  <br>
  <br>
  I'm using phpMailer to send mail from my site using a gmail account.
  <br>
  When I was using this in localhost, everything was fine and mails was sending correctly, 
  But as long as I uploaded my site in remote server, problem revealed itself.
  <br>
  <br>
  There's <code>connection timeout(110) error</code> when I'm using port <code>465</code> and <code>smtp.gmail.com</code>, when I'm trying to use port <code>587</code> and <code>tls</code> there's error too.
  Would you please let me know what's wrong?
  <br>
  <br>
  The host php version is <code>5.4</code>.
  <br><br>
  this is my code:</p>
  
  <pre><code>require_once ("../PHPMailer/class.phpmailer.php");
  
  class mailSender
  {
  
      protected $address;
      protected $username;
      protected $password;
      protected $cc;
      protected $bcc;
  
      protected $body;
  
      protected $mailer;
  
  
      public function __construct( $host, $port, $usn, $psw, $isSMTP = true )
      {
  
          $this-&gt;mailer = new PHPMailer(true);
  
          //$this-&gt;mailer-&gt;Host       = "mail.yourdomain.com"; // SMTP server
          $this-&gt;mailer-&gt;Host       = $host; //"smtp.gmail.com";      // sets GMAIL as the SMTP server
          $this-&gt;mailer-&gt;Port       = $port; //465;                   // set the SMTP port for the GMAIL server
  
  
  
  
          if( $isSMTP == true )
          {
  
              $this-&gt;mailer-&gt;IsSMTP();
              //$this-&gt;mailer-&gt;SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
              $this-&gt;mailer-&gt;SMTPAuth   = true;                  // enable SMTP authentication
              $this-&gt;mailer-&gt;SMTPSecure = "ssl";                 // sets the prefix to the servier
  
          }
  
          $this-&gt;mailer-&gt;Username   = $usn; //"yourusername@gmail.com";  // GMAIL username
          $this-&gt;mailer-&gt;Password   = $psw; //"yourpassword";            // GMAIL password
  
  
          $this-&gt;mailer-&gt;CharSet = 'UTF-8';
  
          $this-&gt;mailer-&gt;IsHTML(true);
  
          //set High priority to prevent going to SPAM folder
          $this-&gt;mailer-&gt;Priority = 1;
          $this-&gt;mailer-&gt;AddCustomHeader("X-MSMail-Priority: High");
          $this-&gt;mailer-&gt;AddCustomHeader("Importance: High");
  
  
      }//function __construct
  
  
  
  
  
      public function send( $address, $senderName, $replyAddr, $replyName, $fromAddr, $fromName, $subject, $body, $attachment = false, $cc = false, $bcc = false )
      {
  
  
        try {
  
            //$this-&gt;mailer-&gt;AddReplyTo( $replyAddr, $replyName);
            $this-&gt;mailer-&gt;AddAddress($address, $senderName);
            $this-&gt;mailer-&gt;SetFrom($fromAddr, $fromName);
            $this-&gt;mailer-&gt;AddReplyTo($replyAddr, $replyName);
            $this-&gt;mailer-&gt;Subject = $subject; //'PHPMailer Test Subject via mail(), advanced';
            $this-&gt;mailer-&gt;AltBody = 'در صورتی که قادر به تماشای محتوای ای-میل نیستید از یک نمایشگر ای-میل تحت HTML استفاده کنید!'; // optional - MsgHTML will create an alternate automatically
            $this-&gt;mailer-&gt;MsgHTML($body);
                //$this-&gt;mailer-&gt;MsgHTML(file_get_contents('contents.html'));
                //$this-&gt;mailer-&gt;AddAttachment('images/phpmailer.gif');      // attachment
                //$this-&gt;mailer-&gt;AddAttachment('images/phpmailer_mini.gif'); // attachment
            $send = $this-&gt;mailer-&gt;Send();
  
            if( $send )
            {
                return true;
  
            }
            else
            {
                return false;
  
            }
        }//try send
        catch( Exception $e )
        {
  
            return false;
  
        }//catch
  
      }//function Send
  
  }//class mailSender
  </code></pre>
  
  <p><strong><em><code>Thanks in Advance</code></em></strong></p>