为什么我看不到已发送电子邮件中上传的附件?
我不知道为什么在发送成功的电子邮件中看不到上传的附件。相反,我看到的是 file: /tump/php/Du460K
而不是实际的附件。
我以为 Mail::
中的 foreach()
会成功,但事实并非如此。
我做错了什么?
这是MailController.php
public function support(Request $request) {
$name = $request->get('name');
$email = $request->get('email');
$file = $request->file('file');
$messageText = $request->get('message');
$data = [
'name' => $name,
'email' => $email,
'file' => $file,
'message' => $messageText
];
Mail::send('email.support.support', $data, function($message) use($file) {
$fileName = $file->getClientOriginalName();
$mimeType = $file->getMimeType();
$message->to('[email protected]');
$data = [
'as' => $fileName,
'mime' => $mimeType
];
if(!empty($file)) {
foreach($file as $userFile) {
$message->attach($userFile->getRealPath(), $data);
}
}
});
view('email.support.support', compact('name', 'email', 'file', 'messageText'));
return Redirect::back()->with('success', 'Successfully submitted!');
}
这是support.blade.php
<div class="container">
<p>Name: {{ $fullName ?? "" }}</p>
<p>Email: {{ $email ?? "" }}</p>
<p>Message: {{ $messageText ?? "" }}</p>
<p>file: {{ $file ?? "" }}</p>
</div>
I'm not sure why I can't see the uploaded attachment in the email that's being sent successfully. Instead, I'm seeing file: /tump/php/Du460K
instead of the actual attachment.
I thought my foreach()
inside Mail::
would've done the trick but it hasn't.
What am I doing wrong?
Here's MailController.php
public function support(Request $request) {
$name = $request->get('name');
$email = $request->get('email');
$file = $request->file('file');
$messageText = $request->get('message');
$data = [
'name' => $name,
'email' => $email,
'file' => $file,
'message' => $messageText
];
Mail::send('email.support.support', $data, function($message) use($file) {
$fileName = $file->getClientOriginalName();
$mimeType = $file->getMimeType();
$message->to('[email protected]');
$data = [
'as' => $fileName,
'mime' => $mimeType
];
if(!empty($file)) {
foreach($file as $userFile) {
$message->attach($userFile->getRealPath(), $data);
}
}
});
view('email.support.support', compact('name', 'email', 'file', 'messageText'));
return Redirect::back()->with('success', 'Successfully submitted!');
}
Here's support.blade.php
<div class="container">
<p>Name: {{ $fullName ?? "" }}</p>
<p>Email: {{ $email ?? "" }}</p>
<p>Message: {{ $messageText ?? "" }}</p>
<p>file: {{ $file ?? "" }}</p>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将文件存储在特定磁盘上,然后将URL返回
actact()
方法检查此
https://laravel.com/docs/9.x/filesystem#file-uploads
我希望这很有帮助
you should store the file on a specific disk and return the URL to
attach()
methodcheck this
https://laravel.com/docs/9.x/filesystem#file-uploads
I hope it's helpful
首先存储图像,然后使用存储的图像路径。
first store the image and then use the stored image path.