首页 > 解决方案 > 使用邮件 laravel 发送生成的二维码

问题描述

大家好,我有一个生成二维码并将其发送到用户的电子邮件的方法,但是二维码 $text 没有显示在电子邮件中,我不知道为什么?

我制作 DD($text) 时的二维码;

Illuminate\Support\HtmlString {#1324 ▼
  #html: """
    <?xml version="1.0" encoding="UTF-8"?>
    <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="200" height="200" viewBox="0 0 200 200"><rect x="0" y="0" width="200" height="200" fill="#ffffff"/> ▶
    """
}

这是控制器方法:

  public static function sendQrcode($id_locateur)
    {

        $locateur = Locateur::findOrFail($id_locateur);
        $info_loc = DB::table('locateurs')
            ->join('confirm_logments', 'confirm_logments.id_Locateur', '=', 'locateurs.id')
            ->join('appartements', 'appartements.id', '=', 'confirm_logments.id_Appartement')
            ->where("locateurs.id", "=", $id_locateur)
            ->get(["locateurs.nom", "locateurs.prenom", "locateurs.Nbr_Invite", "confirm_logments.DateD", "confirm_logments.DateF", "appartements.nom as nomAppartement"])
            ->first();
        setlocale(LC_TIME, 'French');
        $datedebut = Carbon::parse($info_loc->DateD)->formatLocalized('%d %B %Y');
        $datefin = Carbon::parse($info_loc->DateF)->formatLocalized('%d %B %Y');
        $text = (new Generator())->size(200)->generate("Le locateur $info_loc->nom $info_loc->prenom \n(accompagné de ses $info_loc->Nbr_Invite compagnons) \na effectivement loué l'appartement : $info_loc->nomAppartement \nentre le " . $datedebut . " et le " . utf8_encode($datefin));
        Mail::to($locateur->email)->send(new QR($text));
        return view("emails/QR")
            ->with('text', $text);
    }

这是我的 QR.php 课程

class QR extends Mailable
{
    use Queueable, SerializesModels;
    public $text;
    /**
     * Create a new message instance.
     *
     * @return void
     */

    public function __construct($text)
    {
        $this->text = $text;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        // dd($this->text);
        return $this->view('emails.QR');
    }
}

这是我想在电子邮件中显示的视图

<div class="card">
    <div class="card-body">
        <h1>this is your QR code</h1>

{!! $text !!}}

     
    </div>
</div>

标签: laravelemailqr-codelaravel-7laravel-mail

解决方案


推荐阅读