Laravel邮件中的"回复"字段无效

caw*_*coy 22 php email laravel

我需要帮助来弄清楚如何设置reply-to字段app/config/mail.php.我正在使用Laravel 4而且它不起作用.这是我的app/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,
);
Run Code Online (Sandbox Code Playgroud)

Col*_*lin 68

很确定它不会这样工作.您可以在配置文件中设置"From"标题,但在发送期间传递其他所有内容:

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

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

  • - > from($ address,$ name = null)
  • - > sender($ address,$ name = null)
  • - > ReturnPath这样($地址)
  • - >到($ address,$ name = null)
  • - > cc($ address,$ name = null)
  • - > bcc($ address,$ name = null)
  • - > replyTo($ address,$ name = null)
  • - >主题($主题)
  • - >优先级($级)
  • - > attach($ file,array $ options = array())
  • - > attachData($ data,$ name,array $ options = array())
  • - >嵌入($文件)
  • - > embedData($ data,$ name,$ contentType = null)

另外,还有一个神奇的__call方法,因此您可以运行通常在底层SwiftMailer类上运行的任何方法.

  • "Reply-To"标题指定回复邮件时使用的电子邮件地址.该`在-答复To`和/或`References`头应具有相同的值作为原始消息的`消息Id`头,这是邮件客户端如何在一个线程知道该组对话在一起.请参阅https://tools.ietf.org/html/rfc2822#section-3.6.4和http://cr.yp.to/immhf/thread.html (2认同)

chi*_*iii 15

自Laravel 5.3以来,可以添加全局回复.在config/mail.php文件中添加以下内容:

'reply_to' => [
    'address' => 'info@xxxxx.com',
    'name' => 'Reply to name',
],
Run Code Online (Sandbox Code Playgroud)

  • 这个答案是正确的,甚至在Laravel 5.4中也能正常工作.我认为它可以被标记为这个问题的正确答案.由于`env()`函数已在最新版本和`.env`文件中引入,因此它也可以适当使用.`'reply_to'=> ['地址'=> env('MAIL_REPLY_ADDRESS','email @ domain.com'),'name'=> env('MAIL_REPLY_NAME','回复姓名'),],`这个答案有效正好. (2认同)