Skip to content
Advertisement

Problem in Send Mail using Swift Mailer using Office 365

I tried Swift-mailer services for sending mail .. my organization using Outlook 365. Below is the configuration. $transport = (new Swift_SmtpTransport('outlook.office365.com', 587,'tls'))

but i am getting authentication error i tried in gmail. works fine.port number which i tried is 587 as well as 443.. both are showing authentication error. Any idea?

$transport = (new Swift_SmtpTransport('smtp.office365.com', 587,'tls'))

Failed to authenticate on SMTP server with username “Username@Organization.com” using 1 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code “535”, with message “535 5.7.3 Authentication unsuccessful [MAXPR0101CA0037.INDPRD01.PROD.OUTLOOK.COM] “.

Advertisement

Answer

Do you use symfony or you are using the library standalone ?

I’m pretty sure that even the standalone version requires this part:

mailer_transport: smtp
mailer_host: smtp.office365.com
mailer_port: 587
mailer_user: some-user@domain.tld
mailer_password: some-password
mailer_encryption: tls
mailer_delivery_adress: some-email-adress-here

Based on quick look over their docs

    // Create the Transport

$transport = (new Swift_SmtpTransport('smtp.office365.com', 587))
  ->setUsername('your username')
  ->setPassword('your password')
;

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

// Create a message
$message = (new Swift_Message('Wonderful Subject'))
  ->setFrom(['john@doe.com' => 'John Doe'])
  ->setTo(['receiver@domain.org', 'other@domain.org' => 'A name'])
  ->setBody('Here is the message itself')
  ;

// Send the message
$result = $mailer->send($message);
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement