title: Send email via SMTP gmail using php
body: <p>I got this error</p>
  
  <p>Message could not be sent. Mailer Error: SMTP connect() failed.<a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a></p>
  
  <pre><code>$mail = new PHPMailer;
  $mail-&gt;IsSMTP();                                   
  $mail-&gt;Host = 'smtp.gmail.com';                    
  $mail-&gt;SMTPAuth = true;                            
  $mail-&gt;Username = '*****';         
  $mail-&gt;Password = '*****';
  $mail-&gt;SMTPSecure = 'tls';
  $mail-&gt;Port = 587;
  $mail-&gt;SetFrom('*****', 'Innovatory');
  $mail-&gt;AddAddress($f1_email);
  $mail-&gt;isHTML(true);
  $bodyContent = '&lt;br&gt;&lt;h3&gt;From: '.$f1_fname.'&lt;/h3&gt;';
  $bodyContent .= '&lt;b&gt;Company Name: '.$f1_subject.'&lt;br&gt;Mobile: '.$f1_phone.'&lt;br&gt;Email: '.$f1_email.'&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;Service:&lt;/b&gt; '.$f1_message;
  
  $mail-&gt;Subject = 'Contact Email';
  $mail-&gt;Body    = $bodyContent;
  $mail-&gt;mailer="smtp";
  if(!$mail-&gt;send())
  {
      echo 'Message could not be sent. ';
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  }
  else 
  {
      ?&gt;
      &lt;script&gt;
      alert('Mail has been sent.');
      window.location.href='index.php';
      &lt;/script&gt;
      &lt;?php
  }
  </code></pre>