Search code examples
smtpsymfony6

Contact Form Symfony 6 , Error "Expected response code "250", with message "550-Your FROM address"


i have a form that works on the local server without errors, i have implemented it on Hostinger, i have connected the smtp but i get a** 500 error** when i send the form.

I don't understand this error, why is this? I am grateful for any help you can give me.

enter image description here

enter image description here

thank you.

This is my Controller

<?php

namespace App\Controller;

use App\Form\ContactType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Services\EmailService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ContactController extends AbstractController
{
    #[Route('/contacto', name: 'contact')]
    public function index( Request $request, EmailService $emailService): Response
    {

   
        // Contact Form
        $form = $this->createForm(ContactType::class);
        $contact = $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $emailService->send(
                $contact->get('mail')->getData(),
                'proyectos@dijeesco.com.co',
                'Formulario de contacto',
                'contact/email.html.twig',
                [
                    'fullname' => $contact->get('fullname')->getData(),
                    'mail' => $contact->get('mail')->getData(),
                    'telephone' => $contact->get('telephone')->getData(),                    
                    'subject' => $contact->get('subject')->getData(),
                    'message' => $contact->get('message')->getData(),
                ]
            );

            // Flash Message
            $this->addFlash('message', 'Tu mensaje ha sido enviado');
            return $this->redirectToRoute('contact');
        }

        return $this->render('contact/index.html.twig', [           
            'formContact' => $form->createView()
        ]);
    }
    
}

My template enter image description here

My .env

MAILER_DSN=smtp://proyectos@dijeesco.com.co:password@mail.dijeesco.com.co:465 

Solution

  • <?php
    
    namespace App\Controller;
    
    use App\Form\ContactType;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use App\Services\EmailService;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Routing\Annotation\Route;
    
    class ContactController extends AbstractController
    {
        #[Route('/contacto', name: 'contact')]
        public function index( Request $request, EmailService $emailService): Response
        {
    
       
            // Contact Form
            $form = $this->createForm(ContactType::class);
            $contact = $form->handleRequest($request);
    
            if ($form->isSubmitted() && $form->isValid()) {
                $emailService->send(
                    'proyectos@dijeesco.com.co',
                    'proyectos@dijeesco.com.co',
                    'Formulario de contacto',
                    'contact/email.html.twig',
                    [
                        'fullname' => $contact->get('fullname')->getData(),
                        'mail' => $contact->get('mail')->getData(),
                        'telephone' => $contact->get('telephone')->getData(),                    
                        'subject' => $contact->get('subject')->getData(),
                        'message' => $contact->get('message')->getData(),
                    ]
                );
    
                // Flash Message
                $this->addFlash('message', 'Tu mensaje ha sido enviado');
                return $this->redirectToRoute('contact');
            }
    
            return $this->render('contact/index.html.twig', [           
                'formContact' => $form->createView()
            ]);
        }
        
    }