在我的laravel项目后端,我需要跟踪批量邮箱打开,点击,反弹等我使用像素图像来跟踪邮件.当发送邮箱通常使用循环跟踪工作正常.但是当使用cron调度发送邮件时,邮件打开跟踪不起作用.有什么问题?

我的控制器:

Mail::to($this->email)->send(new MarketingMail($this->subject,$this->template,$this->id,  $this->email, $this->file_urls ? $this->file_urls : ''));

Mailable类中的代码:

class MarketingMail extends Mailable
{
    use Queueable, SerializesModels;
    /**
     * Get the message envelope.
     */
    public $subject;
    public $template;
    public $id;
    public $email;
    public $file_url;
    /**
     * Create a new message instance.
     */
    public function __construct($subject,$template,$id, $email, $file_url)
    {
        $this->subject = $subject;
        $this->template = $template;
        $this->id = $id;
        $this->email = $email;
        $this->file_url = $file_url;
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            subject: $this->subject,
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        return new Content(
            view: 'mail.mail',
            with: ['template' => $this->template, 'id' => $this->id],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments()
    {
        if ($this->file_url) {
            foreach ($this->file_url as $file) {
                $this->attach(public_path($file));
            }
        }
    }
}

Blade 文件:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <img src="{{ route('track_open',[$id]) }}" />
    {!! $template !!}
</body>
</html>

正常发送邮件时,跟踪工作正常.但是当使用cron进行调度时,跟踪是不起作用的.什么原因?

推荐答案

我发现问题了.在控制台,在图像路径的尽头出现了http://localhost.这就是问题所在,路径来自.env个Laravel的APP_URL个. 因此,我将值APP_URL更改为.env中的我的域,现在跟踪工作.

Php相关问答推荐

Laravel 9如何过滤$的项目与结果?

Yahoo Finance API文件_GET_CONTENTS 429请求太多

自定义WooCommerce帐户下载列表

使用.htaccess将任何路由重定向到文件

Laravel;Composer安装突然返回选项快捷方式不能为空.

在WooCommerce中禁用特定日期之前的免费送货

如何在函数中定位WooCommerce产品循环

将日期数组排序为年->;月

无法使用php IMAP从Gmail获取收件箱

只收取WooCommerce中最高的运费

在PHP中使用curl命令执行SCRAPYD操作.json不返回任何内容

在WooCommerce中只允许高价产品的BACS付款

如何用Ubuntu 22.04在VSCode中启用XDebug

为什么PHP PDO忽略NOT NULL约束?

Mockery在模拟Redis连接时抛出错误:Mockery\Exception\BadMethodCallException

Laravel withOnly不限制查询

Composer自动加载器重复了子类的类文件路径

Laravel auth()->id() 在生产服务器中不工作

如何将数字文本文件添加到 PHP 数学方程式中?

在全局安装 Composer 包后运行命令