php 为什么我看不到任何电子邮件进入我的邮件捕获器

bttbmeg0  于 2023-01-04  发布在  PHP
关注(0)|答案(1)|浏览(87)

这是我第一次使用邮件捕捉器,我想知道为什么我的代码运行通过发送电子邮件,但我没有看到任何在我的邮件Pig/邮件捕捉器。
下面是我发送电子邮件的方式
配置:

###> symfony/mailer ###
MAILER_DSN=smtp://email@email.com:PASS@sslout.df.eu:465
###< symfony/mailer ###

这些是实际的实时配置,位于我的. env文件中
然后我刮了一个简单的形式

<section>

                {{ form_start(form, {'attr': {'class': 'custom-form'}}) }}

                <form method="post" action="#">
                    <div class="fields">
                        <div class="field half">
                            {{ form_row(form.name, {'attr': {'class': 'form-row'}}) }}
                        </div>
                        <div class="field half">
                            {{ form_row(form.email, {'attr': {'class': 'form-row'}}) }}
                        </div>
                        <div class="field">
                            {{ form_row(form.message, {'attr': {'class': 'form-row'}}) }}
                        </div>
                    </div>
                    <ul class="actions">
                        {{ form_row(form.submit, {'attr': {'class': 'form-row'}}) }}
                    </ul>
                </form>
            </section>

            {{ form_end(form) }}

我就是这样发邮件的

/**
 * @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);

}

当我调试send函数时,它说一切正常并且运行,为什么我在mailhog中看不到我发送的电子邮件

mailhog:
image: mailhog/mailhog
ports:
  - 1025:1025 # smtp server
  - 8025:8025 # web ui
guykilcj

guykilcj1#

以下是它对我的作用

MAILER_DSN=smtp://mailhog:1025

相关问题