Swiftmailer sending email via gmail.com

 
<?php
 
    $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465)
        ->setUsername('yourusername@yourdomain.com')
        ->setPassword('yourpassword')
        ->setEncryption('ssl')
        ->setAuthMode('login');
 
    $mailer = \Swift_Mailer::newInstance($transport);
 
    $message = \Swift_Message::newInstance()
        ->setSubject('Welcome')
        ->setFrom(array('yourusername@yourdomain.com'))
        ->setTo(array('to@to.com'))
        ->setBody('hello world')
        ->setContentType("text/plain");
 
    $mailer->send($message);

Leave a Reply