title: I am trying to configure google SMTP
body: <p>I am trying to configure google SMTP but everytime I am getting SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed error, I've tried multiple solutions but nothing is working here. How to enable smtp mail service. here is my code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Send email via Gmail SMTP server in PHP&lt;/title&gt;
      &lt;link href="css/style.css" rel="stylesheet" type="text/css"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="main"&gt;
          &lt;h1&gt;Send Email via Gmail SMTP Server in PHP&lt;/h1&gt;
          &lt;div id="login"&gt;
              &lt;h2&gt;Send Email&lt;/h2&gt;
              &lt;hr/&gt;
              &lt;form action="index.php" method="post"&gt;
                  &lt;input type="text" placeholder="Enter your Gmail ID" name="email"/&gt;
                  &lt;input type="password" placeholder="Enter your Gmail Password" name="password"/&gt;
                  &lt;input type="text" placeholder="To : Email Id " name="toid"/&gt;  
                  &lt;input type="text" placeholder="Subject : " name="subject"/&gt;
                  &lt;textarea rows="4" cols="50" placeholder="Enter Your Message..." name="message"&gt;&lt;/textarea&gt;
                  &lt;input type="submit" value="Send" name="send"/&gt;
              &lt;/form&gt;    
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;?php
  
          require 'phpmailer/PHPMailerAutoload.php';
          if(isset($_POST['send'])){      
              $mail = new PHPMailer;
              $mail-&gt;SMTPDebug = 2;  //Enable SMTP debugging. 
              $mail-&gt;isSMTP();/*Set mailer to use SMTP*/
              $mail-&gt;Host = 'smtp.gmail.com';/*Specify main and backup SMTP servers*/
              $mail-&gt;Port = 587;
              $mail-&gt;SMTPAuth = true;/*Enable SMTP authentication*/
              $mail-&gt;Username = $email;/*SMTP username*/
              $mail-&gt;Password = $password;/*SMTP password*/
              $mail-&gt;SMTPSecure = 'tls';/*Enable encryption, 'ssl' also accepted*/
              $mail-&gt;From = 'abc';
              //$mail-&gt;FromName = $name;
              $mail-&gt;addAddress('mmmmmm@gmail.com', 'demo');/*Add a recipient*/
              //$mail-&gt;addReplyTo($email, $name);
              /*$mail-&gt;addCC('cc@example.com');*/
              /*$mail-&gt;addBCC('bcc@example.com');*/
              $mail-&gt;WordWrap = 70;/*DEFAULT = Set word wrap to 50 characters*/
              $mail-&gt;addAttachment('../tmp/' . $varfile, $varfile);/*Add attachments*/
              /*$mail-&gt;addAttachment('/tmp/image.jpg', 'new.jpg');*/
              /*$mail-&gt;addAttachment('/tmp/image.jpg', 'new.jpg');*/
              $mail-&gt;isHTML(true);/*Set email format to HTML (default = true)*/
              $mail-&gt;Subject = $subject;
              $mail-&gt;Body    = "&lt;i&gt;Mail body in HTML&lt;/i&gt;";
              $mail-&gt;AltBody = "This is the plain text version of the email content";
              if(!$mail-&gt;send()){
                  echo 'Message could not be sent.';
                  echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
              }else{
                  header("Location: http://cetpatechnologies.com/mail/index.php");
              }
          }
      ?&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>