laravel 5.4来自用户输入的电子邮件附件文件

时间:2017-05-10 02:25:40

标签: php email laravel-5.3

我想在应用程序表单上的用户输入文件中附加电子邮件文件,但我不知道热得好。我尝试了这段代码,但附加文件是在下载附件后打开时无效的文件(图片,pdf等..)。这是我的代码

public function __construct(Request $request, Position $position)
{
    $this->request = $request;
    $this->position = $position;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    $email = $this->from('xxxx@xxxxx.com', $this->request->first_name . ' ' . $this->request->last_name)
        ->replyTo($this->request->email, $this->request->first_name . ' ' . $this->request->last_name)
        ->subject('Application for ' . $this->position->name)
        ->view('emails.application');


        $counter = 1;
        foreach($this->request->resume as $resume) {

            if ($resume->isValid()) {
                $path = $resume->path();
                $extension = $resume->extension();

                $email->attachData($path, 'file' . $counter. '.' . $extension);
            }

            $counter++;
        }

    return $email;
}

0 个答案:

没有答案