I'm developing a site using Laravel 4 and would like to send myself ad-hoc emails during testing, but it seems like the only way to send emails is to go through a view.

Is it possible to do something like this?

Mail::queue('This is the body of my email', $data, function($message)
{
    $message->to('foo@example.com', 'John Smith')->subject('This is my subject');
});

推荐答案

As mentioned in an answer on Laravel mail: pass string instead of view, you can do this (code copied verbatim from Jarek's answer):

Mail::send([], [], function ($message) {
  $message->to(..)
    ->subject(..)
    // here comes what you want
    ->setBody('Hi, welcome user!');
});

您也可以使用空视图,方法是将其放入app/views/email/blank.blade.php

{{{ $msg }}}

没别的了.然后再编写代码

Mail::queue('email.blank', array('msg' => 'This is the body of my email'), function($message)
{
    $message->to('foo@example.com', 'John Smith')->subject('This is my subject');
});

And this allows you to send custom blank emails from different parts of your application without having to create different views for each one.

Laravel相关问答推荐

CKEditor在laravel中的p标记之前和之后添加额外的p标记

如何在 Laravel 中使用多对一变形关系

将错误消息抛出并显示为关联数组

我如何通过 laravel 在高图中针对不同的时间范围进行烛台数据分组

前端和管理员分开时未加载laravel 9中间件

在 laravel 中查询此类数据的最佳做法是什么?

Laravel 5表单请求验证返回禁止错误

Laravel Blade 模板 @foreach 订单

如何在 laravel 中使用 str_replace

Laravel 从现有模型生成迁移

在 Laravel 中下载后如何重定向?

使用 ModelNotFoundException

laravel 4:更新行时如何从列的当前值中减一?

Laravel 全部返回 ID 变为 0

Laravel 邮件密件抄送

Laravel 仓库

Laravel 从公共删除目录

Laravel 4:分析器在哪里?

Eloquent的关系 - attach附加(但不保存)到 Has Many

phpunit 命令不适用于 Windows 7 上的 laravel 4