title: PHP Mailer Not Sending Email To Office365
body: <p>I want to send mail to office365 using phpmailer but its not sending and giving me a connect() error
  here is my code:</p>
  
  <p>email and password which I'm using in real code is perfectly working</p>
  
  <pre><code>require 'mailer/PHPMailerAutoload.php';
  $mail = new PHPMailer();
  $mail-&gt;IsSMTP();
  $mail-&gt;Mailer = 'smtp';
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;Host = 'smtp.office365.com'; // "ssl://smtp.gmail.com" didn't worked
  $mail-&gt;Port = 587;
  $mail-&gt;SMTPSecure = 'tls';
  // or try these settings (worked on XAMPP and WAMP):
  // $mail-&gt;Port = 587;
  // $mail-&gt;SMTPSecure = 'tls';
  
  
  $mail-&gt;Username = "email";
  $mail-&gt;Password = "password";
  
  $mail-&gt;IsHTML(true); // if you are going to send HTML formatted emails
  $mail-&gt;SingleTo = true; // if you want to send a same email to multiple users. multiple emails will be sent one-by-one.
  
  $mail-&gt;Username = "mail@gmail.com";
  $mail-&gt;FromName = "Your Name";
  
  $mail-&gt;addAddress("abc@gmail.com","User 1");
  
  
  $mail-&gt;Subject = "Testing PHPMailer with localhost";
  $mail-&gt;Body = "Hi,&lt;br /&gt;&lt;br /&gt;This system is working perfectly.";
  
  if(!$mail-&gt;Send()) {
      echo "Message was not sent &lt;br /&gt;PHPMailer Error: " . $mail-&gt;ErrorInfo;
  }
  else{
      echo "Message has been sent";
  }
  </code></pre>
  
  <p>the output is</p>
  
  <blockquote>
    <p>Message was not sent 
    PHPMailer Error: SMTP connect() failed. <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a></p>
  </blockquote>