Laravel 邮件中的“回复”字段不起作用

2022-08-30 12:19:37

我需要帮助来弄清楚如何在 中设置字段。我正在使用Laravel 4,但它不起作用。这是我的:reply-toapp/config/mail.phpapp/config/mail.php

<?php

return array(
    'driver' => 'smtp',
    'host' => 'smtp.gmail.com',
    'port' => 587,
    'from' => [
        'address' => 'sender@domain.com',
        'name' => 'E-mail 1'
    ],
    'reply-to' => [
        'address' => 'replyto@domain.com',
        'name' => 'E-mail 2'
    ],
    'encryption' => 'tls',
    'username' => 'sender@domain.com',
    'password' => 'pwd',
    'pretend' => false,
);

答案 1

很确定它不会以这种方式工作。您可以在配置文件中设置“From”标头,但其他所有内容都在发送过程中传递:

Mail::send('emails.welcome', $data, function($message)
{
    $message->to('foo@example.com', 'John Smith')
        ->replyTo('reply@example.com', 'Reply Guy')
        ->subject('Welcome!');
});

FWIW,传递给回调的是 的一个实例,所以有各种方法可以调用它:$messageIlluminate\Mail\Message

  • ->from($address, $name = null)
  • ->sender($address, $name = null)
  • ->返回路径($address)
  • ->to($address, $name = null)
  • ->cc($address, $name = null)
  • ->bcc($address, $name = null)
  • ->replyTo($address, $name = null)
  • ->主题($subject)
  • ->优先级($level)
  • ->attach($file, array $options = array())
  • ->attachData($data, $name, array $options = array())
  • ->嵌入($file)
  • ->embedData($data, $name, $contentType = null)

另外,还有一个神奇的方法,所以你可以运行任何你通常在底层 SwiftMailer 类上运行的方法。__call


答案 2

从Laravel 5.3开始,可以添加全局回复。在您的配置/邮件.php文件中添加以下内容:

'reply_to' => [
    'address' => 'info@xxxxx.com',
    'name' => 'Reply to name',
],

推荐