gpt4 book ai didi

laravel 5.4 在邮件中嵌入图像

转载 作者:行者123 更新时间:2023-12-03 14:38:35 27 4
gpt4 key购买 nike

我刚刚升级了我的 5.2安装 Laravel 到 5.3然后到 5.4按照官方的升级方法。

我现在正在尝试使用其中一项新功能来创建 Markdown 格式的电子邮件。

根据在以下位置找到的文档:https://laravel.com/docs/5.4/mail#view-data

To embed an inline image, use the embed method on the $message variable within your email template. Laravel automatically makes the $message variable available to all of your email templates, so you don't need to worry about passing it in manually:



然而,这:
<img src="{{ $message->embed(public_path().'/img/official_logo.png') }}">

将产生以下错误:

Undefined variable: message



我错过了什么吗?或者升级指南中是否有未记录的内容?

后期编辑:

我正在调用电子邮件功能:
\Mail::to($user)->send(new WelcomeCandidate($user, $request->input('password')));
WelcomeCandidate 看起来像:
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

use App\Models\User;

class WelcomeCandidate extends Mailable
{

use Queueable, SerializesModels;

public $user;
public $password;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(User $user, $password)
{
//
$this->user = $user;
$this->password = $password;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$this->subject('Welcome!');
return $this->markdown('emails.welcome-candidate');
}
}

最佳答案

似乎旧的 $message->embed 不能很好地处理 Markdown 电子邮件。 Like you mentioned in the comments it seems broken since 5.4

但是你可以在你的 Markdown 电子邮件中像这样尝试:

This is your logo 
![Some option text][logo]

[logo]: {{asset('/img/official_logo.png')}} "Logo"

就像这里所示:
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#images

Assets 功能引用: https://laravel.com/docs/5.4/helpers#method-asset

关于laravel 5.4 在邮件中嵌入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42503168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com