Laravel Mail ::发送多个附件

时间:2014-09-18 16:34:13

标签: laravel

如何在laravel中发送包含多个附件的邮件?

这是我的laravel控制器:

public function send_approve_mail($to, $subj, $tmp, $path) {

    $_POST['subj'] = $subj;
    $_POST['to'] = $to;

    foreach ($path as $key => $value) {
        $path[$key] = '../public/assets/fax/extra/' . $value;
    }

    $_POST['attach'] = $path;

    $msg = "test message here";
    $data_mail = Mail::send($tmp, array('msg' => $msg), function($message) {
                $message->from('xxx@xxx.com', $_POST['subj']);
                $message->to($_POST['to'])->subject($_POST['subj']);
                $message->attach($_POST['attach']);
            }, true);

    Help::send_mail($data_mail, array($_POST['to']), array('xxx@xxx.com'));
}

所有附件均可在数组$path中使用。

它显示错误basename() expects parameter 1 to be string, array given

但是,当我使用$_POST['attach'] = $path[0];代替$_POST['attach'] = $path;时,收到的邮件只有一个附件。

1 个答案:

答案 0 :(得分:12)

据我所知,您可以为所有附件使用for循环。有些人喜欢这样:

$data_mail = Mail::send($tmp, array('msg'=>$msg), function($message) use ($path) {
    $message->from('xxx@example.com', $_POST['subj']);
    $message->to($_POST['to'])->subject($_POST['subj']);
    $size = sizeOf($path); //get the count of number of attachments 

    for ($i=0; $i < $size; $i++) {
        $message->attach($path[$i]);
    }
},true);
相关问题