dongpan1308 2014-08-20 17:32
浏览 135
已采纳

发送电子邮件错误

I am using Laravel queues to get my mail working. My SendMail class is as such

class SendMail {
    public static function sendAbuseEmail($job,$data, $toEmail, 
    $subject, $fromEmail, $fromName) {
        Mail::send(array('html' => 'emails.abuseUrl.abuse'), 
                   $data, function ($m) use ($toEmail, $subject, 
                   $fromEmail, $fromName) {
            $m->from($fromEmail, $fromName);
            $m->to($toEmail)->subject($subject);
        });
        $job->delete();
    }
 }

and I am using it as such

$data = array('name' => Input::get('name'), 
              'quote' => Input::get('quote'), 
              'from' => Input::get('email'),
              'abuseUrl'=> Input::get('abuseUrl'));
$subject = Input::get('subject');
$toEmail = Config::get('settings.adminEmail');
$fromEmail = Input::get('email');
$fromName = Input::get('name');
Queue::push('SendMail@sendAbuseEmail', $data,$toEmail, 
           $subject, $fromEmail, $fromName);

but I am getting an error

[2014-08-20 17:25:41] production.ERROR: exception 'ErrorException' with message 'Missing argument 3 for Codeforge\Mailers\SendMail::sendAbuseEmail(), called in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php on line 96 and defined' in /var/www/laravel/app/Codeforge/Mailers/SendMail.php:1

What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • douyun7718 2014-08-20 18:51
    关注

    Take a look at the method signature for QueueInterface#push():

    public function push($job, $data = '', $queue = null);
    

    Where $data can be anything that's json_encodeable. Instead of passing ordered arguments, convention is to pass an associative array:

    Queue::push('SendMail@sendAbuseEmail', array(
        'data' => $data,
        'toEmail' => $toEmail,
        'subject' => $subject,
        'fromEmail' => $fromEmail,
        'fromName' => $fromName
    ));
    

    And in your worker, you can access the values like:

    public static function sendAbuseEmail($job, array $data)
    {
        $toEmail = $data['toEmail'];
        // etc...
    }
    

    This is due to the fact that all drivers (with the exception of the Sync driver) need to serialize this data and write it to some kind of data-store for later reference. I believe it was designed this way because it's just easier to keep track of if it's a single object.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测