title: phpmailer and php5.6 not working with office365
body: <p>I have a site hosted with rackspace and upgraded my site technology from php5.4 to php5.6. Now I can no longer send emails from the site. The worst part is I'm not even getting any errors and the logs show nothing. I am using phpmailer 5.2.14.</p>
  
  <p>Here is my mail script</p>
  
  <pre><code>require 'phpmailer/PHPMailerAutoload.php';
  if (isset($_POST['contactForm'])) {
          $email = $_POST['email'];
          $subject = $_POST['subject'];
          $message = $_POST['message'];
          $body = '
          &lt;html&gt;
              &lt;body&gt;
                  &lt;div style="float:left; width:100%; margin:0 0 25px 0; padding:20px; background:#222; text-align:center;"&gt;
                      &lt;div style="display:inline-block; vertical-align:top;"&gt;
                          &lt;a href="http://website.com"&gt;&lt;img src="img/logoEmail.png" alt="waesf"&gt;&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;main style="float:left; width:100%; padding:20px;"&gt;
                      &lt;p style="font-family:Arial; font-size:18px;"&gt;'.$message.'&lt;/p&gt;
                  &lt;/main&gt;
              &lt;/body&gt;
          &lt;/html&gt;';
          $mail = new PHPMailer;
  
          $mail-&gt;SMTPDebug = 3;                                                         // Enable verbose debug output
  
          $mail-&gt;SMTPOptions = array(
              'ssl' =&gt; array(
                  'verify_peer' =&gt; false,
                  'verify_peer_name' =&gt; false,
                  'allow_self_signed' =&gt; true
              )
          );
          $mail-&gt;isSMTP();                                                                // Set mailer to use SMTP
          $mail-&gt;Host = 'smtp.office365.com';                                             // Specify main and backup SMTP servers
          $mail-&gt;SMTPAuth = true;                                                         // Enable SMTP authentication
          $mail-&gt;Username = 'person@email.com';                                 // SMTP username
          $mail-&gt;Password = 'secret';                                                // SMTP password
          $mail-&gt;SMTPSecure = 'tls';                                                      // Enable TLS encryption, `ssl` also accepted
          $mail-&gt;Port = 587;                                                              // TCP port to connect to
  
          $mail-&gt;SetFrom('person@email.com', 'Ballpoint Machinist');
          $mail-&gt;AddAddress('person@email.com', "BPM");                         // Add a recipient
          $mail-&gt;addReplyTo('person@email.com', 'Information');
          // $mail-&gt;addCC('cc@example.com');
          // $mail-&gt;addBCC('bcc@example.com');
  
          // $mail-&gt;addAttachment('/var/tmp/file.tar.gz');                                // Add attachments
          // $mail-&gt;addAttachment('/tmp/image.jpg', 'new.jpg');                           // Optional name
          $mail-&gt;isHTML(true);                                                            // Set email format to HTML
  
          $mail-&gt;Subject = $subject;
          $mail-&gt;Body    = $body;
          $mail-&gt;AltBody = $body;
  
          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>When the script runs the site then hangs for a while then gives a says server timed out and nothing else. No php error codes nothing and when I check the logs there are no errors related to my mail code. However this only happens with office 365 when I change the smtp settings to gmail then I at least get php errors on the page.</p>
  
  <p>I have already read a bunch of threads on the subject but I fail to understand. I have also gone through <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a> and added the SMTPOptions to exclude ssl but this didn't help.</p>
  
  <p>Im perplexed that I dont get any errors. I have SMTPDebug = 3 and error_reporting(E_ALL).</p>
  
  <p>edit with Willy Pt suggestion. Still doesn't work when script runs server times out.</p>
  
  <pre><code>if (isset($_POST['contactForm'])) {
          $email = $_POST['email'];
          $subject = $_POST['subject'];
          $message = $_POST['message'];
          $body = '
          &lt;html&gt;
              &lt;body&gt;
                  &lt;div style="float:left; width:100%; margin:0 0 25px 0; padding:20px; background:#222; text-align:center;"&gt;
                      &lt;div style="display:inline-block; vertical-align:top;"&gt;
                          &lt;a href="http://website.com"&gt;&lt;img src="img/logoEmail.png" alt="Ballpoint Machinist"&gt;&lt;/a&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;main style="float:left; width:100%; padding:20px;"&gt;
                      &lt;p style="font-family:Arial; font-size:18px;"&gt;'.$message.'&lt;/p&gt;
                  &lt;/main&gt;
              &lt;/body&gt;
          &lt;/html&gt;';
          $mail = new PHPMailer(true);
  
          // $mail-&gt;SMTPDebug = 4;                                                         // Enable verbose debug output
  
          try {
  
          $mail-&gt;SMTPOptions = array(
              'ssl' =&gt; array(
                  'verify_peer' =&gt; false,
                  'verify_peer_name' =&gt; false,
                  'allow_self_signed' =&gt; true
              )
          );
          $mail-&gt;isSMTP();                                                                // Set mailer to use SMTP
          $mail-&gt;Host = 'smtp.office365.com';                                             // Specify main and backup SMTP servers
          $mail-&gt;SMTPAuth = true;                                                         // Enable SMTP authentication
          $mail-&gt;Username = 'person@person.com';                                 // SMTP username
          $mail-&gt;Password = 'test';                                                // SMTP password
          $mail-&gt;SMTPSecure = 'tls';                                                      // Enable TLS encryption, `ssl` also accepted
          $mail-&gt;Port = 587;                                                              // TCP port to connect to
  
          $mail-&gt;SetFrom('person@person.com', 'Ballpoint Machinist');
          $mail-&gt;AddAddress('person@person.com', "BPM");                         // Add a recipient
          $mail-&gt;addReplyTo('person@person.com', 'Information');
          // $mail-&gt;addCC('cc@example.com');
          // $mail-&gt;addBCC('bcc@example.com');
  
          // $mail-&gt;addAttachment('/var/tmp/file.tar.gz');                                // Add attachments
          // $mail-&gt;addAttachment('/tmp/image.jpg', 'new.jpg');                           // Optional name
          $mail-&gt;isHTML(true);                                                            // Set email format to HTML
  
          $mail-&gt;Subject = $subject;
          $mail-&gt;Body    = $body;
          $mail-&gt;AltBody = $body;
          $mail-&gt;send();
          echo "Message Sent OK\n";
          /*if (!$mail-&gt;send()) {
              echo 'Message could not be sent.';
              echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
          } else {
              echo 'Message has been sent';
          }*/
  
  
          } catch (phpmailerException $e) {
              echo $e-&gt;errorMessage(); //Pretty error messages from PHPMailer
          } catch (Exception $e) {
            echo $e-&gt;getMessage(); //Boring error messages from anything else!
          }
      }
  } 
  </code></pre>
  
  <p>Can anyone help?</p>