试图找到一个不存在的文件 Yii2
Trying to find a file that doesnt exist Yii2
我正在尝试创建发送附件的电子邮件功能。
我已经创建了函数并添加了 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
user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35 文件不存在于 app/media/uploads/clinic/monthly-billing/ 文件夹中,甚至不存在于我的数据库中
...怎么了?¿我知道在我的本地,但我不知道尝试搜索不存在的文件的原因,我没有编写任何代码来搜索它,
有人可以帮忙吗?我正在使用 PHPStorm,
非常感谢您的关注!
我不得不清理我的电子邮件队列,它成功了!!非常感谢 Insane Skull 的帮助 ;)
我正在尝试创建发送附件的电子邮件功能。
我已经创建了函数并添加了 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
user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35 文件不存在于 app/media/uploads/clinic/monthly-billing/ 文件夹中,甚至不存在于我的数据库中
...怎么了?¿我知道在我的本地,但我不知道尝试搜索不存在的文件的原因,我没有编写任何代码来搜索它,
有人可以帮忙吗?我正在使用 PHPStorm,
非常感谢您的关注!
我不得不清理我的电子邮件队列,它成功了!!非常感谢 Insane Skull 的帮助 ;)