-1

please, I'm new to Symfony and I'm trying to configure mailer on Symfony 2 but I'm not finding any clear doc for this.

And I'm in need of a route example to send email from an address to another just from back to test this . thank you

I tried installing swift mailer and wrote some code


<?php

namespace MailManager\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

/**
* Email Sender Manager
* @Route("/service-mail/mail")
**/

Class MailManagerController extends AbstractController {

    /**
      * @Route("/send")
      */
      public function send(\Swift_Mailer $mailer){
          $message = \Swift_Message::newInstance()
          ->setsubject('Mail test')
          ->setFrom(['mail@example.com'] => 'xxxxxx')
          ->setTo(['mail1@example.com'] => 'xxxxxx')
          ->setBcc(['mail2@example.com'] => 'vvvvv')
          ->setBody('Test Test');
          $this->get('mailer')
          ->send($message);
      }
}

I expect to send an email from my email address to another email address predefined, automatically when I enter the route in postman.

yivi
  • 42,438
  • 18
  • 116
  • 138
  • 1
    If you are new to symfony, you should not be using version 2.1. Is it an option to use a more modern version (currenlty version 4.3)? – ehymel Jun 19 '19 at 14:10
  • Why there `symfony4` and `symfony-2.1` tag, also you use a version that end of life – Dylan Delobel Jun 19 '19 at 14:41
  • @ehymel in fact i'm working in a big project that is already wrote in symfony 2 so I have to use symfony 2 to develop this project . – M.elabdallah Jun 19 '19 at 15:16
  • Possible duplicate of [Symfony2, send mail to gmail](https://stackoverflow.com/questions/32121424/symfony2-send-mail-to-gmail) – O.Rares Jun 19 '19 at 15:27

1 Answers1

0

Can you change

->setFrom(['mail@example.com'] => 'xxxxxx')
          ->setTo(['mail1@example.com'] => 'xxxxxx')
          ->setBcc(['mail2@example.com'] => 'vvvvv')

By

->setFrom(['mail@example.com' => 'xxxxxx'])
          ->setTo(['mail1@example.com' => 'xxxxxx'])
          ->setBcc(['mail2@example.com' => 'vvvvv'])
mcssym
  • 956
  • 5
  • 8