简体   繁体   English

Laravel,Swiftmailer错误:类不存在

[英]Laravel, Swiftmailer error: Class does not exist

I have a form 我有一个表格

{{ Form::open(array('route' => 'submit.contactAct', 'class' => 'form-horizontal')) }}

            {{ Form::label('fremail', trans('people.email')) }} <span class="req">*</span>
            {{ Form::text('fremail', Input::old('fremail'), array('class' => 'form-control')) }}
            {{ $errors->first('fremail', '<span class="help-block alert alert-danger">:message</span>') }}

            {{ Form::label('comment', trans('people.contact messages')) }} <span class="req">*</span>
            {{ Form::textarea('comment', Input::old('comment'), array('class' => 'form-control', 'rows' => 5)) }}
            {{ $errors->first('comment', '<span class="help-block alert alert-danger">:message</span>') }}

            {{ Form::hidden('email', $actor['email']) }}

            {{ Form::submit('Submit', array('class' => 'btn btn-success')) }}

        {{ Form::close() }}

It has three fields: a from email field ('fremail'), a 'comment' field and a 'email' field which grabs the email from the 'actor' database table. 它具有三个字段:“发件人”电子邮件字段(“ fremail”),“评论”字段和“电子邮件”字段,可从“参与者”数据库表中获取电子邮件。

My submit function looks like this. 我的提交功能如下所示。 It validates the data and sends it to a send function. 它验证数据并将其发送到发送功能。 It also creates a $star variable and stores the 'email' field. 它还创建一个$ star变量并存储“电子邮件”字段。 For this example the email stored in $star=actorname@gmail.com 对于此示例,电子邮件存储在$star=actorname@gmail.com中

public function submitContactAct()
{

    //prepare input
    $input = Input::except('_token');
            $star = Input::get('email');

    if ( ! $this->validator->with($input)->passes())
    {
        return Redirect::back()->withErrors($this->validator->errors())->withInput($input);
    }


    $this->mailer->sendContactUsAct($input, $star);

    return Redirect::back()->withSuccess( trans('main.contact success') );
}

This is my send email function, I have set the setReplyTo to the $star variable, but I keep receiving Class actorname@gmail.com does not exist 这是我的发送电子邮件功能,我已经将setReplyTo设置为$ star变量,但是我一直在接收Class actorname@gmail.com不存在

public function sendContactUsAct(array $input, $star)
{
       //get contact us email for db

            $options = App::make('Options');
    $email = $options->getContactEmail();

    if ($email)
    {
        Mail::send('Emails.ContactAct', $input, $star, function($message) use($email)
        {
                    $message->setReplyTo($star);
            $message->to($email)->subject( trans('main.contact email subject') );
        });
    }
}

I don't know why it is thinking a the string in $star is a class. 我不知道为什么它认为$ star中的字符串是一类。

Try this 尝试这个

Mail::send('Emails.ContactAct', $input, function($message) use ($email, $star)
{
    $message->setReplyTo($star);
    message->to($email)->subject( trans('main.contact email subject') );
});

Variable $star has to be passed using use because it's not in scope of your closure. 变量$star必须使用use传递,因为它不在关闭范围之内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM