title: SMTP Connection Timeout PHP Email
body: <p>Please read before marking this as a duplicate. I have tried everything!</p>
  
  <p>I have been trying to use SwiftMailer and PHPMailer, both which I have use before, to send emails from my website form. For some reason, for the last few days, I haven't gotten them to work. Each time, no matter the settings, I get error 110 - Connection timeout to the smtp server. I have tried using authentication from my gmail account and 1and1.com email account. I have even added a check using <code>fsockopen</code> and gmail, godaddy nor 1and1's smtp server can be connected to. And I've even called 1and1 twice to ask about firewalls and anything that would prevent my emails and they've said they don't know what the problem could be. I have tried everything listed on multiple Stackoverflow questions and cannot fix this. Is there anything going on that would prevent this? My internet connection (tried home and work) maybe? I'm very lost! My code for PHPMailer and SwiftMailer will be pasted below. Please remember that I have tried using port 465/ssl and port 587/tls and neither has worked.</p>
  
  <pre><code>require 'PHPMailerAutoload.php';
  
  $mail = new PHPMailer();
  $mail-&gt;isSMTP();
  $mail-&gt;Host = 'smtp.example.com';
  $mail-&gt;Port = 465;
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Username = 'inquiry@example.com';
  $mail-&gt;Password = 'password';
  $mail-&gt;SMTPSecure = 'ssl';
  $mail-&gt;From = 'inquiry@example.com';
  $mail-&gt;addAddress('example@gmail.com');
  $mail-&gt;isHTML(true);
  
  $checkconn = fsockopen($mail-&gt;Host, $mail-&gt;Port, $errno, $errstr, 5);
  
  if($_GET['formName'] == 'join')
  {
      $text = 'Name: &lt;b&gt;' . $_POST['first_name_join']. " " .$_POST['last_name_join']. "&lt;/b&gt;".
               "&lt;br&gt;Phone: &lt;b&gt;".$_POST['phone_join']. "&lt;/b&gt;".
               "&lt;br&gt;Email: &lt;b&gt;".$_POST['email_join']. "&lt;/b&gt;".
               "&lt;br&gt;Date of Birth: &lt;b&gt;".$_POST['birth_month']. "/" .$_POST['birth_day']. "/" .$_POST['birth_day']. "&lt;/b&gt;".
               "&lt;br&gt;Message: &lt;br&gt;&lt;b&gt;".$_POST['message_join']. "&lt;/b&gt;";
  }
  else
  {
      $text = 'Name: &lt;b&gt;' . $_POST['full_name_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Company/Organization: &lt;b&gt;" . $_POST['company_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Phone: &lt;b&gt;".$_POST['phone_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Email: &lt;b&gt;".$_POST['email_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Message: &lt;br&gt;&lt;b&gt;".$_POST['message_sponsor']. "&lt;/b&gt;";
  }
  
  
  
  $mail-&gt;Subject = $_GET['formName'] == 'join' ? 'Join Inquiry' : 'Sponsorship Inquiry' ;
  $mail-&gt;Body    = $text;
  
  if (!$checkconn)
  {
      echo "($errno) $errstr\n\n";
  }
  if(!$mail-&gt;send()) {
      echo 'Message could not be sent.';
      echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
  } else {
      echo 'Message has been sent';
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>require_once 'swiftmailer/swift_required.php';
  
  
  // Create the Transport
  $transport = Swift_SmtpTransport::newInstance('smtp.example.com', 587)
      -&gt;setUsername('inquiry@example.com')
      -&gt;setPassword('password');
  
  
  // Create the Mailer using your created Transport
  $mailer = Swift_Mailer::newInstance($transport);
  
  if($_GET['formName'] == 'join')
  {
      $text = 'Name: &lt;b&gt;' . $_POST['first_name_join']. " " .$_POST['last_name_join']. "&lt;/b&gt;".
               "&lt;br&gt;Phone: &lt;b&gt;".$_POST['phone_join']. "&lt;/b&gt;".
               "&lt;br&gt;Email: &lt;b&gt;".$_POST['email_join']. "&lt;/b&gt;".
               "&lt;br&gt;Date of Birth: &lt;b&gt;".$_POST['birth_month']. "/" .$_POST['birth_day']. "/" .$_POST['birth_day']. "&lt;/b&gt;".
               "&lt;br&gt;Message: &lt;br&gt;&lt;b&gt;".$_POST['message_join']. "&lt;/b&gt;";
  }
  else
  {
      $text = 'Name: &lt;b&gt;' . $_POST['full_name_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Company/Organization: &lt;b&gt;" . $_POST['company_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Phone: &lt;b&gt;".$_POST['phone_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Email: &lt;b&gt;".$_POST['email_sponsor']. "&lt;/b&gt;".
               "&lt;br&gt;Message: &lt;br&gt;&lt;b&gt;".$_POST['message_sponsor']. "&lt;/b&gt;";
  }
  
  // Create a message
  $subject = $_GET['formName'] == 'join' ? 'Join Inquiry' : 'Sponsorship Inquiry' ;
  $message = Swift_Message::newInstance($subject)
    -&gt;setFrom(array('inquiry@example.com'))
    -&gt;setTo(array('example@gmail.com')) 
    -&gt;setBody($text, 'text/html');
  
  // Send the message
  $result = $mailer-&gt;send($message);
  </code></pre>