I have installed MailCatcher in my Symofny 4.2 project.
I have configured it in my .env file:
MAILER_URL=http://127.0.0.1:1080/
And in swiftmailer.yml
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
parameters:
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
mailer_port: 1025
When I open that url, mail inbox loads correctly.
I trigger my __invoke function while persisting some entity and want to catch mail I am sending.
I am using API platform so it's tricky to find out where the problem is.
Here is an error:
Entity is peristed in the db but mail has not been send.
I tried changing the response but no luck. I am stuck with this error.
public function __invoke()
{
$transport = (new Swift_SmtpTransport('127.0.0.1', 1025));
$mailer = new Swift_Mailer($transport);
$message = (new \Swift_Message('Hello Email'))
->setFrom('send@example.com')
->setTo('recipient@example.com')
->setBody('My <em>name</em> is Filip', 'text/plain');
$mailer->send($message);
return new JsonResponse(['result' => 'ok']);
}
}