php-swiftmailerHow to use Swiftmailer with IMAP?
Swiftmailer can be used with IMAP to send and receive emails. To use Swiftmailer with IMAP, you need to create a Transport instance with the IMAP host, port, username, and password.
$transport = (new Swift_SmtpTransport('imap.example.com', 993, 'ssl'))
->setUsername('[email protected]')
->setPassword('yourpassword');
The code above creates a Transport instance with the IMAP host, port, username, and password.
Once the Transport instance is created, you can use it to send and receive emails.
$mailer = new Swift_Mailer($transport);
$message = (new Swift_Message('Wonderful Subject'))
->setFrom(['[email protected]' => 'John Doe'])
->setTo(['[email protected]', '[email protected]' => 'A name'])
->setBody('Here is the message itself')
;
$result = $mailer->send($message);
The code above creates a Mailer instance with the Transport instance and sends an email.
Helpful links
More of Php Swiftmailer
- How to set timeout with Swiftmailer?
- How to use SMTP with Swiftmailer?
- How to use TLS 1.2 with Swiftmailer?
- How to get the response code when using Swiftmailer?
- How to use Swiftmailer to send RFC 2822 compliant emails?
- How to configure Swiftmailer for Postfix?
- How to send emails in UTF8 using Swiftmailer?
- How to send emails to multiple recipients with Swiftmailer?
- How to set the port for Swiftmailer?
- How to enable TLS with Swiftmailer?
See more codes...