mail icon indicating copy to clipboard operation
mail copied to clipboard

求助 发送邮件只有标题没有内容

Open daniuwo opened this issue 4 years ago • 6 comments

收到的邮件只有标题没有内容

<?php

declare(strict_types=1);

namespace App\Mail;

use HyperfExt\Contract\ShouldQueue;
use HyperfExt\Mail\Mailable;

class UserEmailCode extends Mailable implements ShouldQueue
{
    public $code;

    /**
     * Create a new message instance.
     * @param mixed $code
     */
    public function __construct($code = '')
    {
        $this->code = $code;
    }

    /**
     * Build the message.
     */
    public function build()
    {
        return $this->subject('账号注册验证码')->textView('email/user_email_code');
    }
}

发送代码

Mail::to($this->request->input('email'))->queue(new MailUserEmailCode($code));

用的ThinkTemplate 引擎/storage/view/email/user_email_code.html

您的验证码是:{$code},请不要把验证码泄露给其他人,如非本人操作请不用理会!

daniuwo avatar Apr 18 '21 07:04 daniuwo

config 确认过吗

ericyzhu avatar May 24 '21 15:05 ericyzhu

遇到同样问题

micross avatar Aug 02 '21 15:08 micross

应该是邮件模板修改后,缓存尚未生成,而生成文件是协程里完成的,估计还是hyperf的bug,我们临时的做法是提前生成模板视图

gokure avatar Aug 26 '21 10:08 gokure

就是视图缓存没生成导致的,在邮件的构造方法里预先编译对应的视图文件即可解决(如图。当然,只要你能在使用视图前确保视图缓存文件已生成,理论上都是可以的,比如你甚至可以在config/container.php里面批量生成,只是这样做破坏了框架原有的结构)。 image

RFireStorm avatar Sep 08 '21 03:09 RFireStorm

就是视图缓存没生成导致的,在邮件的构造方法里预先编译对应的视图文件即可解决(如图。当然,只要你能在使用视图前确保视图缓存文件已生成,理论上都是可以的,比如你甚至可以在config/container.php里面批量生成,只是这样做破坏了框架原有的结构)。 image

我也遇到这个问题, 你这个确实能解决。 大佬提个PR给统一解决了吧?

Hhhha avatar Dec 13 '21 07:12 Hhhha

还有其他最新的解决方法吗

fsp1234567 avatar Mar 01 '23 08:03 fsp1234567