预期的响应代码"250/251/252",但得到代码"530",并带有消息"530 SMTP authentication is required."


###> symfony/mailer ###
MAILER_DSN=smtp://localhost
###< symfony/mailer ###

这是我的.env的一部分
我试图在用户注册后发送电子邮件
,但我不知道该在MAILER DSN中放入什么,我收到了这个错误
错误最后但同样重要的是,这是我的邮件服务

<?php
namespace AppService;
use SymfonyBridgeTwigMimeTemplatedEmail;
use SymfonyComponentMailerMailerInterface;
use SymfonyComponentMimeAddress;
class Mailer{
/**
* @var MailerInterface
*/
private $mailer;
public function __construct(MailerInterface $mailer)
{
$this->mailer = $mailer;
}
public function sendMail($email, $token){
$email = (new TemplatedEmail())
->from('Lost-found@foundonly.com')
->to(new Address($email))
->subject('Thanks for signing up! Just one more thing to do')
// path of the Twig template to render
->htmlTemplate('emails/signup.html.twig')
// pass variables (name => value) to the template
->context([
'token' => $token,
])
;
$this->mailer->send($email);
}
}

最后是寄存器控制器

<?php
namespace AppController;
use AppEntityUser;
use AppFormRegisterType;
use AppServiceMailer;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;

class RegisterController extends AbstractController
{
/**
* @var UserPasswordEncoderInterface
*/
private $passwordEncoder;

/**
* @var Mailer
*/
private $mailer;
public function __construct(UserPasswordEncoderInterface $passwordEncoder, Mailer $mailer)
{
$this->passwordEncoder = $passwordEncoder;
$this->mailer = $mailer;
}
/**
* @Route("/signup", name="signup")
* @throws Exception
*/
public function register(Request $request): Response
{
$user = new User();
$form = $this->createForm(RegisterType::class,$user);
$form->handleRequest($request);
if($form->isSubmitted()&&$form->isValid()){
$user->setPassword(
$this->passwordEncoder->encodePassword($user,$form->get("password")->getData())
);
$user->setToken($this->generateToken());
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$this->mailer->sendMail($user->getEmail(),$user->getToken());
$this->addFlash("success", "you are more than welcome into our community, just one more step | Check your mail please");
}//37.12
return $this->render('register/register.html.twig',[
'form' => $form->createView()
]);
}
/**
* @throws Exception
*/
private function generateToken(): string
{
return rtrim(strtr(base64_encode(random_bytes(32)),'+/','-_'),'=');
}
}
?>

有人能帮我吗?我真的不知道该在邮件中放什么

您需要正确配置Mailer传输。它可以是SMTP服务器,也可以是本地sendmail二进制文件。

如果你不想麻烦发送邮件,而更喜欢使用SMTP传输,最简单的解决方案是使用带有symfony/google mailer组件的gmail SMTP服务器

更多信息:使用Mailer发送电子邮件

最新更新