laravel具有向两个用户使用不同的视图页面发送两个邮件的相同功能

时间:2018-08-29 07:32:48

标签: laravel laravel-5 laravel-5.4

In laravel cron i have a function like  given below :
public function booking_mail()
{
  $data_to_mail= DB::table('tbl_booking as book')
                ->select('book.id as book_id','book.*','twd.id as wk_id','twd.*')
                ->join('tbl_workers_details as twd', 'twd.id', '=', 'book.worker_id')
                ->where('book.status','=','0')
                ->get();

            $data['viewpage']='mailtemplates.booking';
            $data['toemail']=$agent[0]->email;
            $data['listing_no']=$data_to_mail[0]->listing_no;
            $data['cv_no']=$data_to_mail[0]->cv_no;


            $mail= Mail::send($data['viewpage'], ['userdata'=>$data], function ($message) 
                use ($data) {
                        $message->to($data['toemail'],'Booking Mail')->subject('Inquiry Mail For Booking');
                if($data['attach']!=''){ 

                    $message->attach($data['attach']);
                }           
            });

            if($data['attach']!=''){ 
                unlink($data_to_mail[0]->civil_id_copy);
            }
            $result=DB::table('tbl_booking')
          ->where('id','=',$data_to_mail[0]->book_id)
          ->update(array(
          'status'=>'1',
          ));

}
  

此功能工作正常,但是当我为邮件功能添加了一个功能时   在函数的末尾,它不起作用,返回错误。一世   不知道为什么这发生在我身上。我想要这样做,因为我想要   为具有两个不同数据的两个不同用户发送邮件,以及   查看代码在下面给出,返回错误。

public function booking_mail()
{
  $data_to_mail= DB::table('tbl_booking as book')
                ->select('book.id as book_id','book.*','twd.id as wk_id','twd.*')
                ->join('tbl_workers_details as twd', 'twd.id', '=', 'book.worker_id')
                ->where('book.status','=','0')
                ->get();

  $data['user_viewpage']='mailtemplates.enduser_booking';
                    $data['toemail']=$agent[0]->email;
                    $data['listing_no']=$data_to_mail[0]->listing_no;
                    $data['cv_no']=$data_to_mail[0]->cv_no;

    //send e-mail to the agent for booking
                    $mail= Mail::send($data['viewpage'], ['userdata'=>$data], function ($message) 
                        use ($data) {
                                $message->to($data['toemail'],'Booking Mail')->subject('Inquiry Mail For Booking');
                        if($data['attach']!=''){ 

                            $message->attach($data['attach']);
                        }           
                    });

                    $mail= Mail::send($data['user_viewpage'], ['userdata'=>$data], function ($message) 
                        use ($data) {
                                $message->to($data['toemail'],'Booking Mail')->subject('Confirmation mail');       
                    });

                    $result=DB::table('tbl_booking')
                  ->where('id','=',$data_to_mail[0]->book_id)
                  ->update(array(
                  'status'=>'1',
                  ));

} 

为什么会发生这种情况,并返回以下错误:

StreamBuffer.php第268行中的Swift_TransportException:无法与主机mail.XXXX.com建立连接[连接超时#110]

1 个答案:

答案 0 :(得分:0)

您未定义$data["user_viewpage"]