1

I am having some trouble figuring out why my emails are not being sent out to my Office 365 account. Before my companies migration to Office 365 we had an internal mail server and getting emails to send out was a piece of cake. However, now that we have moved to Office 365 it has become a real headache getting emails to send out. I thought that maybe I needed to set up an SMTP Relay and point to that server in my php code but it seems that is not the issue. Below is my code used to send out a test email:

$from = "example@example.com";
$to = "test_user@example.com";
$bcc = '';
$subject = "Hi!";
$body = "Hi,\n\nLooks like it worked.";

$host = 'smtp.office365.com';
$port = '587';
$username = 'example@example.com'; 
$password = '**********';

$headers = array(
 'Port'          => $port,
 'From'          => $from,
 'To'            => $to,
 'Subject'       => $subject,
'Content-Type'  => 'text/html; charset=UTF-8'
);

$recipients = $to.", ".$bcc;

$smtp = Mail::factory('smtp',
 array ('host' => $host,
 'auth' => true,
 'username' => $username,
 'password' => $password));

$mail = $smtp->send($recipients, $headers, $body);

echo "test";

if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
} else {
   echo("<p>Message successfully sent!</p>");
}

Once I run this code I am presented with the following error:

authentication failure [SMTP: SMTP server does not support authentication (code: 250, response: SN1PR19CA0003.outlook.office365.com Hello [68.15.136.46] SIZE 157286400 PIPELINING DSN ENHANCEDSTATUSCODES XXXXXXXA 8BITMIME BINARYMIME XXXXXXXB)]

I have researched the heck out of this error and have had no luck in resolving my issue. I am wondering if it has something to do with the fact that the server I am generating the php code on is a development server and not on a live site. I am thinking that since this is not a live site I need to point it to a server that uses SMTP relay in order to get it out onto the internet, however, like I said I have had no luck when doing this.

Any assistance is greatly appreciated.

Thanks in advance.

Brandon
  • 49
  • 1
  • 11

0 Answers0