试图找到一个不存在的文件Yii2

时间:2019-05-09 09:44:57

标签: yii yii2 swiftmailer

我正在尝试创建一个发送附件文件的电子邮件功能。

我已经创建了函数,并向我要附加的文件路径添加了attach(),如下所示:

public function newMonthlyBillingRegister(Clinic $clinic, ClinicMonthlyBilling $clinicMonthlyBilling)
{
    $countryAdmins = $clinic->findCountryAdmins($clinic->country->id);
    $adminEmails = [];

    foreach ($countryAdmins as $admin) {
        $adminEmails[$admin->email] = $admin->fullName;
    }

    /** @var BaseMailer $mailer */
    $mailer = Yii::$app->mailer;

    $mailer->htmlLayout = 'layouts/standard_html';
    //$mailer->htmlLayout = 'layouts/invoice_html';
    // $mailer->textLayout = 'layouts/invoice_text';

    try{
        return $mailer
                ->compose(
                    ['html' => 'newMonthlyBillingRegister-html', 'text' => 'newMonthlyBillingRegister-text'],
                    [
                        'clinic'               => $clinic,
                        'clinicMonthlyBilling' => $clinicMonthlyBilling,
                    ]
                )
                ->setFrom([Yii::$app->params['supportEmail'] => Yii::t('app', 'support-email-name', ['appName' => Yii::$app->name])])
                ->setTo($adminEmails)
                ->setSubject(Yii::t('app', '[CLINIC][BACKOFFICE] A clinic has upgraded its information in Guarantee Fund Modal.'))
                ->attach('app/media/uploads/clinic/monthly-billing/'.$clinicMonthlyBilling->trimestralBillingFile)
                ->queue() && YII_DEBUG && Yii::$app->mailqueue->process();
    }
    catch(\Exception $e){
        LogService::getLogger()->error("Error while sending mail.","EmailService:newMonthlyBillingRegister()",$e->getMessage());
    }
}

它给了我一个错误,但是问题出在我从代码中删除attach(),还原了对该电子邮件功能的所有更改,并且当我尝试再次发送电子邮件时,出现以下消息:

PHP Warning: fopen(app/media/uploads/clinic/monthly-billing/user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35): failed to open stream: No such file or directory in /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 142

app / media / uploads / clinic / monthly-billing /文件夹甚至我的数据库中都不存在user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35文件

...怎么了?我知道在我的本地,但是我不知道尝试搜索不存在的文件的原因,并且我没有编写任何代码来搜索它,

任何人都可以帮忙吗?我正在使用PHPStorm,

非常感谢您的关注!

1 个答案:

答案 0 :(得分:0)

我必须清理我的电子邮件队列,并且能正常工作!!非常感谢Insane Skull的帮助;)