PHPMailer error Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
<p>Hi i am trying to use PHPMailer its not working giving me error</p>

<blockquote>
  <p>Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()</p>
</blockquote>

<p>here is my code </p>

<pre><code>     require_once('mailFiles/PHPMailerAutoload.php');
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."&lt;br/&gt;";
                $mail = new PHPMailer();
                $mail-&gt;isSMTP();
                $mail-&gt;SMTPDebug = 4;
                $mail-&gt;Debugoutput = 'html';
                $mail-&gt;SMTPAuth = true;
                $mail-&gt;SMTPSecure = 'ssl';
    //            $mail-&gt;SMTPSecure = 'tls';
                $mail-&gt;Host = 'smtp.gmail.com';
    //            $mail-&gt;Host = gethostbyname('smtp.gmail.com');
    //            $mail-&gt;Host = 'tls://smtp.gmail.com:587';
    //            $mail-&gt;Port = 587;
                $mail-&gt;Port = 465;
                $mail-&gt;Username = "xs4arabiabahrain@gmail.com";
                $mail-&gt;Password = "mailpass";
                $mail-&gt;setFrom('mail@gmail.com', 'Firstz Last');
                $mail-&gt;addAddress('myemail@gmail.com', 'MAAGE-EMAIL User');
                $mail-&gt;IsHTML(true);

                //Set the subject line
                $mail-&gt;Subject = 'PHPMailer GMail SMTP test';
                //Read an HTML message body from an external file, convert referenced images to embedded,
                //convert HTML into a basic plain-text alternative body
                $mail-&gt;msgHTML('Hi test 123');
                //Replace the plain text body with one created manually
                $mail-&gt;AltBody = 'This is a plain-text message body';
                //Attach an image file
                //$mail-&gt;addAttachment('images/phpmailer_mini.png');
                $result = $mail-&gt;send();
                if (!$result) {
                    echo ("Mailer Error: "); 
                    echo ($mail-&gt;ErrorInfo);
                } else {
                    echo ("Message sent!"); 
                }
</code></pre>

<p>Have tired <strong>tls</strong> still not working.</p>