在 Symfony 中覆盖默认邮件程序 URL
Override default mailer URL in Symfony
我正在尝试让用户有可能在 Symfony 中向我发送电子邮件,我可以向自己发送电子邮件,但我无法从其他电子邮件中获取电子邮件,因为 .env 中给出的默认电子邮件地址文件未被覆盖。
/**
* @Route("/send_msg", name="send_msg", methods={"GET","POST"})
*/
public function index(Request $request, \Swift_Mailer $mailer)
{
$name = $request->query->get('name');
$mail = $request->query->get('mail');
$msg = $request->query->get('msg');
$message = (new \Swift_Message('Client'))
->setFrom($mail)
->setTo('my_gmail@gmail.com')
->setBody($msg)
;
$mailer->send($message);
return new JsonResponse();
}
这是 .env 文件
###> symfony/mailer ###
# MAILER_DSN=smtp://localhost
###< symfony/mailer ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=gmail://my_gmail@gmail.com:my_pass@localhost
###< symfony/swiftmailer-bundle ###
###> symfony/sendgrid-mailer ###
#MAILER_DSN=sendgrid://KEY@default
###< symfony/sendgrid-mailer ###
您正在使用 Gmail 凭据作为 SMTP 服务器。您不能也不应该通过您的 Gmail 凭据从任何其他电子邮件地址发送邮件。即使您使用的是另一个允许任何发件人地址的 SMTP 服务器,您也不应该使用在您的 SMTP 服务中未经过身份验证的电子邮件地址作为发件人地址,因为您的电子邮件可能永远不会出现在收件箱中。
一个选项是使用 $message->setReplyTo($mail);
将回复地址设置为您用户的电子邮件地址。这样,如果您点击邮箱中的回复按钮,邮件将发送至用户的电子邮件地址。
我正在尝试让用户有可能在 Symfony 中向我发送电子邮件,我可以向自己发送电子邮件,但我无法从其他电子邮件中获取电子邮件,因为 .env 中给出的默认电子邮件地址文件未被覆盖。
/**
* @Route("/send_msg", name="send_msg", methods={"GET","POST"})
*/
public function index(Request $request, \Swift_Mailer $mailer)
{
$name = $request->query->get('name');
$mail = $request->query->get('mail');
$msg = $request->query->get('msg');
$message = (new \Swift_Message('Client'))
->setFrom($mail)
->setTo('my_gmail@gmail.com')
->setBody($msg)
;
$mailer->send($message);
return new JsonResponse();
}
这是 .env 文件
###> symfony/mailer ###
# MAILER_DSN=smtp://localhost
###< symfony/mailer ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=gmail://my_gmail@gmail.com:my_pass@localhost
###< symfony/swiftmailer-bundle ###
###> symfony/sendgrid-mailer ###
#MAILER_DSN=sendgrid://KEY@default
###< symfony/sendgrid-mailer ###
您正在使用 Gmail 凭据作为 SMTP 服务器。您不能也不应该通过您的 Gmail 凭据从任何其他电子邮件地址发送邮件。即使您使用的是另一个允许任何发件人地址的 SMTP 服务器,您也不应该使用在您的 SMTP 服务中未经过身份验证的电子邮件地址作为发件人地址,因为您的电子邮件可能永远不会出现在收件箱中。
一个选项是使用 $message->setReplyTo($mail);
将回复地址设置为您用户的电子邮件地址。这样,如果您点击邮箱中的回复按钮,邮件将发送至用户的电子邮件地址。