Integrating SwiftMailer into your PHP project is straightforward. Here’s a quick guide:
Install SwiftMailer: You can install it via Composer using the command: composer require swiftmailer/swiftmailer
Set Up the Transport: Configure the transport method you wish to use, such as SMTP. $transport = (new Swift_SmtpTransport('smtp.example.com', 25)) ->setUsername('your username') ->setPassword('your password');
Create the Mailer: Use the transport to create a mailer instance. $mailer = new Swift_Mailer($transport);
Compose the Message: Create a message instance and set the necessary parameters. $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 Email: Finally, send the composed message. $result = $mailer->send($message);