Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Allow to set plain HTML in mails #22809

Merged
merged 4 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BadMethodCallException;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Container\Container;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Contracts\Queue\Factory as Queue;
Expand Down Expand Up @@ -64,6 +65,13 @@ class Mailable implements MailableContract, Renderable
*/
protected $markdown;

/**
* The HTML to use for the message.
*
* @var string
*/
protected $html;

/**
* The view to use for the message.
*
Expand Down Expand Up @@ -185,6 +193,12 @@ public function render()
*/
protected function buildView()
{
if (isset($this->html)) {
return array_filter([
'html' => new HtmlString($this->html),
'text' => isset($this->textView) ? $this->textView : null,
]);
}
if (isset($this->markdown)) {
return $this->buildMarkdownView();
}
Expand Down Expand Up @@ -585,6 +599,19 @@ public function markdown($view, array $data = [])
return $this;
}

/**
* Set the HTML content for the message.
*
* @param string $html
* @return $this
*/
public function html($html)
{
$this->html = $html;

return $this;
}

/**
* Set the view and view data for the message.
*
Expand Down
13 changes: 13 additions & 0 deletions src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Swift_Mailer;
use InvalidArgumentException;
use Illuminate\Support\HtmlString;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Htmlable;
Expand Down Expand Up @@ -159,6 +160,18 @@ public function raw($text, $callback)
return $this->send(['raw' => $text], [], $callback);
}

/**
* Send a new message when only a html part.
*
* @param string $html
* @param mixed $callback
* @return void
*/
public function html($html, $callback)
{
return $this->send(['html' => new HtmlString($html)], [], $callback);
}

/**
* Send a new message when only a plain part.
*
Expand Down