繁体   English   中英

如何使用 LARAVEL 在 mailgun header 中发送数据?

[英]How to send data in the mailgun header with LARAVEL?

我第一次使用 webhook,其中我必须传递一些为稍后定义的 3 个变量,当 Laravel 再次使用它时,我可以更新为某些报告发送的 email 的操作。

问题是我无法在 email 的 header 中传递数据。

这是通常将 email 发送给用户的结构:


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

public function build()
{
    $message = $this->data;
    // print_r($variables);
    // exit;
    return $this->from(config('mail.from.address'), config('mail.from.name'))
                ->view($this->view)
                ->subject($this->subject); //WORKED

/**NO WORKED*/
                ->withSwiftMessage(function ($message) use ($v){
                    $v->getHeaders()
                    ->addTextHeader('Custom-Header', 'HeaderValue1')
                    ->addTextHeader('Custom-Header2', 'HeaderValue2');
                });
}

如果发送的邮件没有问题,邮件中填写的视图和数据,但在 header 中至少在这种情况下没有填写数据,2个变量设置 ['Custom-Header' , 'HeaderValue1', 'Custom-Header', 'HeaderValue2]。

我也遇到了同样的问题,我花了很多时间研究和测试。 它似乎需要采用 json 格式,并且您需要使用“X-Mailgun-Variables”而不是“Custom-Header”。 它应该看起来像这样

->addTextHeader('X-Mailgun-Variables', '{"variable1": "1", "variable2": "2"}')

webhook 应该给你这个结果

  "user-variables":{
     "variable1":"1",
     "variable2":"2"
  },

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM