title: symfony contact form is submitted but emails dont arrive
body: <p>I need some help regarding sending emails in symfony 4.</p>
  
  <p>I made a contact form in symfony 4.
  where i use formbuilder and swiftmailer. The contact form works, it validates and i can submit. but emails don't arrive plus i don't get a confirmation message on the contactpage itself after sending.
  i use mailer with host of the website itself. The website is in production mode.</p>
  
  <p>See below the code i used. Maybe i missed some settings? thanks in advance!</p>
  
  <p>ContactType.php</p>
  
  <pre><code>&lt;?php
  // your-path-to-types/ContactType.php
  
  namespace App\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\Form\Extension\Core\Type\TextType;
  use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  use Symfony\Component\Form\Extension\Core\Type\EmailType;
  
  class ContactType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('name',TextType::class);
          $builder-&gt;add('email',EmailType::class);
          $builder-&gt;add('subject',TextType::class);
          $builder-&gt;add('body',TextareaType::class);
      }
  
      public function getBlockPrefix()
      {
          return 'contact';
      }
  }
  </code></pre>
  
  <p>Contact.php my entity  </p>
  
  <pre><code>&lt;?php
  
  // src/Entity/Contact.php
  
  
  namespace App\Entity;
  
  use Symfony\Component\Validator\Mapping\ClassMetadata;
  use Symfony\Component\Validator\Constraints\NotBlank;
  use Symfony\Component\Validator\Constraints\Email;
  use Symfony\Component\Validator\Constraints\Length;
  use Doctrine\Common\Collections\ArrayCollection;  
  
  class Contact
  
  {
  
      protected $name;
      protected $email;
      protected $subject;
      protected $body;
      public function getName()
  
      {
          return $this-&gt;name;
      }
  
  
  
      public function setName($name)
  
      {
          $this-&gt;name = $name;
      }
  
  
  
      public function getEmail()
  
      {
          return $this-&gt;email;
      }
  
  
  
      public function setEmail($email)
  
      {
          $this-&gt;email = $email;
      }
  
  
  
      public function getSubject()
  
      {
          return $this-&gt;subject;
      }
  
  
  
      public function setSubject($subject)
  
      {
          $this-&gt;subject = $subject;
      }
  
  
  
      public function getBody()
  
      {
          return $this-&gt;body;
      }
  
  
  
      public function setBody($body)
  
      {
          $this-&gt;body = $body;
  
      }
  
      public static function loadValidatorMetadata(ClassMetadata $metadata)
      {
          $metadata-&gt;addPropertyConstraint('name', new NotBlank());
  
          $metadata-&gt;addPropertyConstraint('email', new Email());
  
          $metadata-&gt;addPropertyConstraint('subject', new NotBlank());
          $metadata-&gt;addPropertyConstraint('subject', new Length(array('max'=&gt; 50)));
  
          $metadata-&gt;addPropertyConstraint('body', new Length(array('min'=&gt; 5)));
      }
  
  }
  </code></pre>
  
  <p>and my controller</p>
  
  <pre><code>&lt;?php
  namespace App\Controller;
  
  use App\Entity\Contact;
  use App\Form\ContactType;
  
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Annotation\Route;
  use Symfony\Component\HttpFoundation\Request;
  
  
  final class PagesController extends DefaultController
  
  {
  
  
      /**
       * @Route("/contact", name="contact")
       * @Method("GET|POST")
       */
      public function contact(Request $request,  \Swift_Mailer $mailer)
      {
  
          $enquiry = new Contact();
          $form = $this-&gt;createForm(ContactType::class, $enquiry);
  
           $this-&gt;request = $request;
              if ($request-&gt;getMethod() == 'POST') {
              $form-&gt;handleRequest($request);
  
              if ($form-&gt;isValid()) {
  
  
                          $message = (new \Swift_Message('Hello Email'))
                              -&gt;setFrom('contact@example.com')
                              -&gt;setTo('xxxxxxx@gmail.com')
                              -&gt;setBody($this-&gt;renderView('contact/contactEmail.txt.twig', array('enquiry' =&gt; $enquiry)));
                          $mailer-&gt;send($message);
  
                      $this-&gt;get('session')-&gt;getFlashbag('blog-notice', 'Your contact enquiry was successfully sent. Thank you!');
  
  
                  // Redirect - This is important to prevent users re-posting
                  // the form if they refresh the page
                  return $this-&gt;redirect($this-&gt;generateUrl('contact'));
  
              }
          }
  
          return $this-&gt;render('pages/contact.html.twig', array(
              'form' =&gt; $form-&gt;createView(),
          ));
      }
  
  
  }
  </code></pre>
  
  <p>and in my <em>main.env</em> file i have this</p>
  
  <pre><code>MAILER_URL=smtp://localhost:25?encryption=ssl&amp;auth_mode=login&amp;username=xxx&amp;password=xxxx
  </code></pre>
  
  <p>So email does not get delivered. After submit I am transferred back to contact page, and no flash message either :/
  Have I missed anything else for this to work?</p>
  
  <p><strong><em>example:</em></strong>  </p>
  
  <ul>
  <li>does my username have to be a whole email address that I also need to decode, etc?</li>
  <li>do I need to change something on the server also? please advise.</li>
  </ul>