title: phpmailer / IsSMTP causes 500 error but sends the mail 1 minute later
body: <p>whenever $mail->isSMTP(); is set in phpmailer it "hangs" for about 1 minute, then it redirects to a:
  500 Service Unavailable page with XID: 2060448470.</p>
  
  <p>BUT one minute later i GET the mail that was sent. in the mail i can read:
  Received-SPF: pass (google.com: domain of admin@skivbasar.se designates 2a00:16d8:0:4::200 as permitted sender) </p>
  
  <p>When i remove "$mail->isSMTP();" the email get sent right away BUT they dont get SPI = pass:
  spf=none (google.com: 117658@atapa01.citynetwork.se does not designate permitted sender hosts).</p>
  
  <p>I really need SMTP to work since i got a lots of lost mails in the past. I've spent several days looking for a solution including 20+articles here on stackoverflow.</p>
  
  <p>I've re-tried the sample code several times from both worxware and github. It's always "$mail->isSMTP();" that refuses to work propperly.</p>
  
  <p>Here is my mail code:</p>
  
  <pre><code>require("PHPMailerAutoload.php");
  require("class.phpmailer.php");
  require("class.smtp.php");
  
  $mail = new PHPMailer();
  $mail-&gt;Host = "mail.skivbasar.se";
  $mail-&gt;Port = 587;
  $mail-&gt;SMTPAuth = true;    
  $mail-&gt;SMTPSecure = "ssl";
  $mail-&gt;IsSMTP();   
  $mail-&gt;Username = "-----.se";  // SMTP username
  $mail-&gt;Password = "-------"; // SMTP password
  $mail-&gt;AddReplyTo($replyto);
  $mail-&gt;From     = "admin@skivbasar.se";
  $mail-&gt;FromName = "skivbasar.se";
  $mail-&gt;AddAddress($row['email']);
  $mail-&gt;Subject  = $row['subject'];
  $mail-&gt;Body     = $row['message'];
  $mail-&gt;WordWrap = 150;
  
  if(!$mail-&gt;Send()) {
      $error = true;
  } else {
  
      $error = false;
  }
  </code></pre>
  
  <p>you can access a testpage to see the error in action at: <a href="http://skivbasar.se/action/mail/t3.php" rel="nofollow">http://skivbasar.se/action/mail/t3.php</a></p>
  
  <p>UPPDATE:</p>
  
  <p>Thank you so much for replying Synchro! You seem to be a real phpmailer expert!</p>
  
  <p>i've tried both tls and ssl countless times and even commenting the line and using both port 587 and 465. Both actually works to send mail as long as "isSMTP" is of.</p>
  
  <p>The real problem i'm trying to solve is why the script hangs for 1 minute whenever "isSMTP" is set but still send the mail after redirecting to the 500 page.</p>
  
  <p>the softfail ones without isSMTP is being sent by:
  from smtp02.mailout.citynetwork.se (mailout.citynetwork.se. [91.123.193.90])</p>
  
  <p>and the passed (but hanged) ones are being sent by:
  from smtp03.citynetwork.se (mail.citynetwork.se. [91.123.193.200]).</p>
  
  <p>Is feels like the script is waiting for a reply from the mailserver for 60 seconds (like a HELO) and when the server does not respond. it send the mail anyway after 60 minutes. I've read about this somewhere. I also found some entries in the code where it refers to "HELO" like in class.phpmailer.php on line 1340 "// We must resend HELO after tls negotiation".</p>
  
  <p>Since it's redirect to a 500 page i cant print any error messages. I also dont have access to my log. But it works with "isSMTP" on localhost, it's only when the script is run online is hangs like this.</p>