Reputation: 287
I am trying to send an email with swift mailer using Exchange authentication. However, I can't seem to figure out why it doesn't work.
<?php
require_once( "./application/helpers/swift/swift_required.php" );
$transport =
Swift_SmtpTransport::newInstance( "31.149.66.10", 25 )
->setUsername( "username" )
->setPassword( 'password' )
->setEncryption( "tls" );
$mailer = Swift_Mailer::newInstance( $transport );
$message = Swift_Message::newInstance( "onderwerp" )
->setFrom( array( "[email protected]" ) )
->setTo( array( "[email protected]" ) )
->setBody( "Body van het bericht" );
var_dump( $mailer->send( $message ) );
?>
This gives me the error: Uncaught exception 'Swift_TransportException' with message 'Failed to authenticate on SMTP server with username "nieuwsbrief" using 0 possible authenticators'.
The server is configured to use TLS and basic authentication (Offer Basic authentication only after starting TLS).
I saw that some people use port 587 for TLS encryption, but I can't connect on port 587. That gives the error: Connection could not be established with host 31.149.66.10 [No route to host #113].
Can anyone see what I'm doing wrong?
Upvotes: 1
Views: 7497
Reputation: 7694
If an Exception of type Swift_TransportException will be thrown it means the authentication fails.
to know early whether or not authentication has failed and an Exception is going to be thrown, call the start()
method on the created Transport
The following checklist will help you find the problem with this kind of error:
function stream_get_transports()
For example you can add it by adding this in php.ini
extension=php_openssl.dll
Upvotes: 1