Here we will learn how to send emails using swift mailer , few steps you have to follow first you have to install swift mailer sdk via composer then include the autoload.php file in your project.

install swiftMailer

Create composer.json file and paste this code and open command window and execute command composer update

    "require": {
        "swiftmailer/swiftmailer": "^6.0"

Then open command window and execute this this query

This command will download all your necesarry packages about swiftmailer 

Then Create the index.php file

<!DOCTYPE html>
        <meta charset="UTF-8">
    <body style="background: #ccc;">
        <form action="" method="post" style="font-size: 25px;background: #fff;padding: 40px;width: 400px;margin: 100px auto;">
            <h2>Swift Mailer</h2>
            if (isset($_POST['email'])) {

                require_once './vendor/autoload.php';

// Create the Transport
                $transport = (new Swift_SmtpTransport('', 25))

// Create the Mailer using your created Transport
                $mailer = new Swift_Mailer($transport);

// Create a message
                $message = (new Swift_Message('Please subscrible my channel'))
                        ->setFrom(['' => 'Tech. Rudranshi'])
                        ->setTo([$_POST['email'] => 'gajanand'])
                        ->setBody('Thanks for subscribing us ,Here is the message to email.');

                if ($mailer->send($message) == TRUE) {
                    echo "Email sent to " . $_POST['email'];

            <input type="text" name="email" placeholder="Enter your email"><input type="submit" value="Mail Me" >

Add your smtp username and password it will work


Download source code

Are you facing problems in understanding this article? download source code now