简体   繁体   English

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

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

I am working with webhooks for the first time, in which I have to pass some 3 variables defined for later when Laravel takes it again I can update an action of the email sent for some reports.我第一次使用 webhook,其中我必须传递一些为稍后定义的 3 个变量,当 Laravel 再次使用它时,我可以更新为某些报告发送的 email 的操作。

The problem is that I can't pass data in the header of the email.问题是我无法在 email 的 header 中传递数据。

This is the structure that commonly sent the email to the users:这是通常将 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');
                });
}

The emails if sent in that there is no problem, with the view and the data that is filled in the mail, but in the header the data is not filled in at least in this case, the 2 variables set ['Custom-Header', 'HeaderValue1', 'Custom-Header', 'HeaderValue2].如果发送的邮件没有问题,邮件中填写的视图和数据,但在 header 中至少在这种情况下没有填写数据,2个变量设置 ['Custom-Header' , 'HeaderValue1', 'Custom-Header', 'HeaderValue2]。

I had the same problem too and it took me quite a bit of research and testing.我也遇到了同样的问题,我花了很多时间研究和测试。 It seems that it needs to be in json format and you need to use 'X-Mailgun-Variables' instead of 'Custom-Header'.它似乎需要采用 json 格式,并且您需要使用“X-Mailgun-Variables”而不是“Custom-Header”。 It should look like this它应该看起来像这样

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

the webhook should give you this result webhook 应该给你这个结果

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

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

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