如何发送主题和内容变量与队列邮件

时间:2017-09-23 15:25:58

标签: php laravel email laravel-5 laravel-5.5

我试图发布电子邮件后发布邮件时发送邮件但当我尝试添加变量主题时显示我错误undefined $ blog 这是我的控制器

$blog = new Blog;
    $blog->title = $request->title;
    $blog->content = $request->content;
    $blog->slug = str_slug($blog->title, '-');
    $blog->user_id = Auth::user()->id;
    $blog->published_at = $request->published_at;
    if($request->hasFile('image')) {
        $file = Input::file('image');
        //getting timestamp
        $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
        $name = $timestamp. '-' .$file->getClientOriginalName();
        $file->move(public_path().'/images/blog/', $name);
        $blog->image = $name;
        $thumb = Image::make(public_path().'/images/blog/' . $name)->resize(640,420)->save(public_path().'/images/blog/thumb/' . $name, 90);
    }
    $blog->save();
$subscribers = Subscriber::get();
    foreach ($subscribers as $subscribe) {
        $mail = Mail::to($subscribe->email)->send(new BlogPost($blog));
    }


    return Redirect::back()->with('status', 'Post Success');

这是我在app / mail /

上的电子邮件类BlogPost.php
    <?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class BlogPost extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($blog)
    {
        $this->blog = $blog;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.new_blog')
                    ->subject('this is test email subject')
                    ->with([
                        'title'     =>  'This is Testing Email',
                        'content'     =>  'this is something else',
                    ]);
    }
}

我遗失了一些我不知道或者我不知道如何将变量发送到主题,标题或内容的内容

0 个答案:

没有答案