我正在尝试发送带有动态 SMTP 连接参数的电子邮件。这些参数将从数据库中检索。因此,按照官方文档中的说明在文件中指定参数.env
(例如MAILER_DSN=smtp://user:pass@smtp.example.com:port
:)或在文件中定义多重传输不符合我的要求。.yaml
如何以编程方式发送定义邮件传输的电子邮件?例如,我想做:
// I'd like to define $customMailer with some data retrieved from DB
$email = (new TemplatedEmail())
->from(new Address('example-from@example.com', 'Example'))
->to('example-to@example.com')
->subject('Subject')
->htmlTemplate('emails/my-template.html.twig')
->context([]);
$customMailer->send($email);