getUser(); if($user != $offer->getByUser()) { $email = (new TemplatedEmail()) ->from(new Address('no-reply@pflaenz.li', 'Pflänzli no-reply')) ->to($offer->getByUser()->getEmail()) ->replyTo($user->getEmail()) ->subject($user->getUsername() . ' wants to trade with you!') ->text('Trade offer') ->htmlTemplate('user/trade/offer_email.html.twig') ->context([ 'user' => $user, 'urlId' => $user->getUrlId(), ]) ; try { $mailer->send($email); $this->addFlash('success', 'Trade offer sent!'); } catch (TransportExceptionInterface $e) { $this->addFlash('error', 'There was an error: ' . $e); } } else { $this->addFlash('error','You can\'t trade with yourself!'); } return $this->redirectToRoute('show_offer', ['urlId' => $offer->getUrlId()]); } }