【发布时间】:2021-02-08 11:54:38
【问题描述】:
我在 yii2 中使用 swiftmailer 时遇到问题。
'components' => [
'mailer' => [
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.mandrillapp.com',
'port' => 587,
'username' => 'noreply@mysociete.com',
'password' => 'MY API KEY HERE',
],
],
],
在用户注册后发送我使用下面的代码:
$isSuccessfullySaved = $leadModel->save();
if (!$isSuccessfullySaved) {
$response = $this->asJson(['errors' => ['webservice' => 'Error while saving the lead']]);
$response->statusCode = 550;
return $response->send();
}
$lastStep = Json::decode(file_get_contents(__DIR__ . '/../config-offers/offers.json'));
$isSuccessfullySent = Yii::$app->mailer->compose(
'offer-summary',
ArrayHelper::merge($leadModel->getAttributes(), $lastStep['offres'][$bestOffer])
)
->setFrom(['noreply@mysociete.com' => 'My Societe'])
->setTo($leadModel->emailAddress)
->setSubject('mysociete.com- Votre offre')
->send();
if (!$isSuccessfullySent) {
Yii::error("Could not send the email", __METHOD__);
}
应该有什么问题。任何日志中都没有写入错误。
【问题讨论】:
-
查看
->send();返回的内容
标签: yii2 swiftmailer