【发布时间】:2020-02-27 15:09:46
【问题描述】:
我试图让用户可以在 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 ###
【问题讨论】:
标签: php symfony gmail swiftmailer