it's my first time using mail catcher and I was wondering why my code runs through for sending an e-mail but I don't see anything in my mail hog / mail catcher.
Here is how I send my e-mail
Config:
###> symfony/mailer ###
MAILER_DSN=smtp://[email protected]:[email protected]:465
###< symfony/mailer ###
These are the actual live configs, which are in my .env file
Then I shave a simple form
<section>
{{ form_start(form, {'attr': {'class': 'custom-form'}}) }}
<form method="post" action="#">
<div >
<div >
{{ form_row(form.name, {'attr': {'class': 'form-row'}}) }}
</div>
<div >
{{ form_row(form.email, {'attr': {'class': 'form-row'}}) }}
</div>
<div >
{{ form_row(form.message, {'attr': {'class': 'form-row'}}) }}
</div>
</div>
<ul >
{{ form_row(form.submit, {'attr': {'class': 'form-row'}}) }}
</ul>
</form>
</section>
{{ form_end(form) }}
And this is how I send my e-mail
/**
* @var MailerInterface
*/
private MailerInterface $mailer;
/**
* @param MailerInterface $mailer
*/
public function __construct(MailerInterface $mailer)
{
$this->mailer = $mailer;
}
#[Route('/', name: 'app_contact')]
public function index(Request $request)
{
$form = $this->createForm(ContactFormType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
try {
$this->sendMail(
$data['name'],
$data['email'],
$data['message'],
);
} catch (\Exception $e) {
$e->getMessage();
}
header('/');
// return $this->render('contact/success.html.twig');
}
return $this->render('contact/contact.html.twig', [
'form' => $form->createView()
]);
}
/**
* @param MailerInterface $mailer
* @throws \Symfony\Component\Mailer\Exception\TransportExceptionInterface
*/
public function sendMail($name, $email, $message)
{
$sendTo = 'contact@build-yourself';
$email = (new Email())
->from($email)
->to($sendTo)
->subject('Contact Email from: ' . $name)
->text($message);
$this->mailer->send($email);
}
When I debug the send function it says that everything is okay and it runs, why can't I see my sent e-mail inside my mailhog
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025 # smtp server
- 8025:8025 # web ui
CodePudding user response:
This problem has already been solved, here you will find the answer of your problem.
CodePudding user response:
Here is how it worked for me
MAILER_DSN=smtp://mailhog:1025