如何在laravel5.5中发送多封电子邮件

时间:2017-12-27 11:30:30

标签: php laravel email

我想发送多封电子邮件。我使用下面的代码发送多封电子邮件: -

$emails = ['ab.in@gmail.com', 'ka.in@gmail.com'];

    Mail::send('emails.email-marketing-template', [], function($message) use ($emails)
    {    
        $message->to($emails)->subject('This is test e-mail');    
    });
    var_dump( Mail:: failures());
    exit;

如果我将其发送给单个用户,它可以正常工作,但不适用于多个用户。我该如何向多个用户发送电子邮件?

2 个答案:

答案 0 :(得分:5)

来自the 5.5 docs

  

to方法接受电子邮件地址,用户实例或用户集合。如果您传递对象或对象集合,邮件程序将在设置电子邮件收件人时自动使用其library(shiny) library(Ecdat) attach(Benefits) u <- shinyUI(pageWithSidebar( headerPanel("Social benefits"), sidebarPanel( selectInput("variable1", "Zmienna X:", list("Bezrobocie" = "stateur", "Max zasilek" = "statemb", "Wiek" = "age", "Staz w bezrobociu" = "tenure", "Replacement rate" = "rr" )), selectInput("variable2", "Zmienna Y:", list("Bezrobocie" = "stateur", "Max zasilek" = "statemb", "Wiek" = "age", "Staz w bezrobociu" = "tenure", "Replacement rate" = "rr" )), selectInput("points", "Punkty:", list("Powod utraty pracy" = "joblost", "Plec" = "sex", "Nie-bialy" = "nwhite", ">12 lat szkoly" = "school12", "Robotnik fizyczny" = "bluecol", "Mieszka w miescie" = "smsa", "Zonaty" = "married", "Ma dzieci" = "dkids", "Male dzieci" = "dykids", "Glowa rodziny" = "head", "Otrzymuje zasilki" = "ui" )), checkboxInput("reg", "Pokaz krzywa regresji", FALSE) ), mainPanel( plotOutput("Plot") ) )) s <- shinyServer(function(input, output) { formula <- reactive({paste(input$variable2,"~",input$variable1)}) caption <- renderText({formula()}) pkt <- reactive({input$points}) #pkt <- renderText({paste(input$points)}) output$Plot <- renderPlot({ plot(as.formula(formula()),data=Benefits, main = caption(), pch = as.numeric(input$points), col=as.numeric(input$points)) if(input$reg == TRUE){ abline(lm(as.formula(formula())),col ="red", lwd = 2) legend("topleft",inset = 0.02, legend = "Krzywa regresji", col="red",lty = 1, lwd = 2) } }) }) shinyApp(u,s) email属性,因此请确保这些属性在您的对象上可用。

所以,你可以这样做:

name

或者您可以使用$users = User::get(); Mail::to($users)->send(new OrderShipped($order)); name键传递数组:

email

答案 1 :(得分:0)

我更喜欢通过queue / spool从Laravel和Symfony发送电子邮件。详细了解queueing emails in Laravel

队列电子邮件比立即发送邮件更好,因为支持请求的主进程不等待电子邮件发送过程。

如果您使用Mail:queue,则可以循环向多个收件人发送电子邮件