How to configure laragon/sendmail with Symfony

Viewed 19

I'm trying to configure a Symfony 6.1 project to send mail through a fresh installed laragon and sendmail, but all my tries were unsuccessful.

I tried with many configuration and this one doesn't trigger error, but I don't receive any mail and any debug message :

#.env
MAILER_DSN=smtp://localhost
#php.ini

[mail function]
; For Win32 only.
; https://php.net/smtp
SMTP = localhost
; https://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; https://php.net/sendmail-from
;sendmail_from = me@example.com

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; https://php.net/sendmail-path
;sendmail_path =

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail().
;mail.force_extra_parameters =

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
sendmail_path="C:/laragon/bin/sendmail/sendmail.exe"

; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
; Log mail to syslog (Event Log on Windows).
;mail.log = syslog
<?php

// src/Controller/MailerController.php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;

class MailerController extends AbstractController
{
  #[Route('/email')]
  public function sendEmail(MailerInterface $mailer): Response
  {
    $email = (new Email())
      ->from('noreply@mydomain.com')
      ->to('nobody@gmail.com')
      ->subject('Time for Symfony Mailer!')
      ->text('Sending emails is fun again!')
      ->html('<p>See Twig integration for better HTML integration!</p>');

    try {
      $mailer->send($email);
    } catch (TransportExceptionInterface $e) {
      die("debug:".$e->getDebug());
    }

    return new Response('ok');
  }
}

The route to test : http://127.0.0.1:8000/email

Result :

enter image description here

0 Answers
Related