Sending mail using Office 365 in zend framework fail

107 Views Asked by At

I am working on a zend framework version 1 which is an extremely old project. I had to implement a email feature on that project and for local development mailtrap was doing completely okay but when it was time to host it on live i wanted to use office365 but gives me an issue.

function sendUserEmail($toEmail, $fromEmail, $subject, $body)
{
    $mail = new Zend_Mail();
    $mail->setFrom($fromEmail);
    $mail->addTo($toEmail);
    $mail->setSubject($subject);
    $mail->setBodyText($body);

    // Retrieve SMTP configuration from the application configuration
    $config = Zend_Controller_Front::getInstance()->getParam('bootstrap');
    $smtpConfig = $config->getOptions()['mail']['transport'];

    // Set up SSL configuration
    $ssl = !empty($smtpConfig['ssl']) ? $smtpConfig['ssl'] : null;

    $smtpOptions = [
        'auth' => 'login',
        'username' => office365email,
        'password' => office365password,
        'ssl' => null,
        'port' => 587,
    ];

    // Create an SMTP transport using the provided host and SMTP options
    $transport = new Zend_Mail_Transport_Smtp($smtpConfig['host'], $smtpOptions);
    // Send the email using the configured transport
    return $mail->send($transport);
}

This is the function that i use send email. It works for sendgrid, mailtrap and other but only doesn't work for office365

I have set SSL null becuase if i use "TLS" it says "Couldn't connect via tls" and when i put "SSL" it couldn't open socket.

The main error message is 504 5.7.4 Unrecognized authentication type

0

There are 0 best solutions below