Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel-电子邮件附件未定义变量_Php_Laravel - Fatal编程技术网

Php Laravel-电子邮件附件未定义变量

Php Laravel-电子邮件附件未定义变量,php,laravel,Php,Laravel,我有三个用户可以上传的文件,但问题是如果没有附加图像,它会抛出一个未定义的变量错误,因为没有传递任何内容,主要问题是附件是通过url定义的,因此当我向其添加null值或“”时,它会抛出一个超时错误 有没有更好的方法来解决这个问题 if ($request->file('img_1')) { $file = $request->file('img_1'); $image_name1 = time()."-".$file->getCl

我有三个用户可以上传的文件,但问题是如果没有附加图像,它会抛出一个未定义的变量错误,因为没有传递任何内容,主要问题是附件是通过url定义的,因此当我向其添加null值或“”时,它会抛出一个超时错误

有没有更好的方法来解决这个问题

if ($request->file('img_1')) {
            $file = $request->file('img_1');
            $image_name1 = time()."-".$file->getClientOriginalName();

            if ($file->move('uploads/quote', $image_name1)) {
                $enquiry->img_1 = $image_name1;
                $enquiry->save();
            }
        }else{
            $image_name1 = '';
        }
这是我在此之后使用的函数

function ($message) use ($request, $image_name1, $image_name2, $image_name3) {

                $name_input = $request['name'];
                $company_name = 'Test';

                $message->to($sendto_email, '')->from('alerts@testing.com', 'Quote')->subject('New Quote from ' . $name_input )->attach('uploads/quote/' . $image_name1)->attach('uploads/quote/' . $image_name2)->attach('uploads/quote/' . $image_name3);
        });
编辑:
主要是$message to part,找到一种方法,在未选择/未设置特定图像时不添加->附加

$images = [$image_name1, $image_name2, $image_name3];

function ($message) use ($request, $images) {

    $name_input = $request['name'];
    $company_name = 'Test';

    $message->to($sendto_email, '')->from('alerts@testing.com', 'Quote')->subject('New Quote from ' . $name_input);

    foreach ($images as $image) {
        $message->attach('uploads/quote/' . $image);
    }