php-swiftmailerHow to set the port for Swiftmailer?
Swiftmailer can be configured to use a specific port for sending emails.
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.example.org', 25))
->setUsername('your username')
->setPassword('your password')
;
// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);
The example code above creates a transport object with the hostname smtp.example.org
and port 25
.
Code explanation
Swift_SmtpTransport
: This is the class used to create a transport object.smtp.example.org
: This is the hostname of the SMTP server.25
: This is the port number used to connect to the SMTP server.setUsername
andsetPassword
: These methods are used to set the username and password for authentication.
Helpful links
More of Php Swiftmailer
- How to set the 'from' address in Swiftmailer?
- How to configure Swiftmailer for SMTP without authentication?
- How to set timeout with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to send emails in UTF8 using Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to configure Swiftmailer for Postfix?
- How to use Swiftmailer with SendGrid?
- How to encrypt emails with SwiftMailer?
- How to enable TLS with Swiftmailer?
See more codes...