How to send a letter to symfony to help swift mailer



  • I'd like to send a letter from the locol server using a swiftmailer and a gmail to symfony. These are code fragments.

    /src/MailerBundle/controller/defaultController
    

    <?php

    namespace MailerBundle\Controller;

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;

    class DefaultController extends Controller
    {
    public function indexAction()
    {
    $Request = $this->getRequest();
    if($Request->getMethod()=="POST") {
    $name = $Request->get('name');
    $email = $Request->get('email');
    $subject =$Request->get('subject');
    $message = $Request->get('message');
    $message = \Swift_Message::newInstance()
    ->setSubject($subject)
    ->setFrom($email)
    ->setTo('any@whatever.com')
    ->setBody('ExampleBundle:Default:mail.html.twig', 'text/html');

    Send the message

            $this-&gt;get('mailer')
                -&gt;send($message);
        }
        return $this-&gt;render('MailerBundle:Default:index.html.twig');
    }
    

    }

    //config_dev.yml
    swiftmailer:
    transport: %dev_mailer_transport%
    host: %dev_mailer_host%
    username: %dev_mailer_user%
    password: %dev_mailer_password%
    spool: { type: memory }
    //parameters.yml

    This file is auto-generated during the composer install

    parameters:
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: null
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    secret: 3rw23ewre343ewrew3434rwrew34343wre

    Mail setup for development environment

    dev_mailer_transport: gmail
    dev_mailer_host: null
    dev_mailer_user: example@gmail.com
    dev_mailer_password: password

    Mail setup for production environment

    prod_mailer_transport: smtp
    prod_mailer_host: localhost
    prod_mailer_user: null
    prod_mailer_password: null

    But somehow it's not working, it's been overprotected. Help!



  • Maybe it's a two-factor copying problem on your record. gmail♪ In this case, it will be necessary. https://support.google.com/accounts/answer/185833 individual password for application and use it Parameter mailer_password

    Also the recipe book. symfony http://symfony.com/doc/current/cookbook/email/gmail.html I'll see you. https://support.google.com/accounts/answer/6010255 I don't know.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2