【问题标题】:SwiftMailer - Yii2 can't send emailSwiftMailer - Yii2 无法发送电子邮件
【发布时间】: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


【解决方案1】:

您是否尝试过在传输中设置加密?我不确定 Mandrillapp 是否需要它,但您可以尝试一下:

'transport'        => [
  'class'    => 'Swift_SmtpTransport',
  'host'     => 'smtp.mandrillapp.com',
  'port'     => 587,
  'username' => 'noreply@mysociete.com',
  'password' => 'MY API KEY HERE',
  'encryption' => 'tls',
],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多