dte66654 2017-05-12 11:43
浏览 134
已采纳

在Laravel 5中使用不同的回复发送电子邮件

I have this email configurated in Laravel with SMTP. It works well.

I want some users to be able to send emails with their own e-mail address.

I used to do this:

Mail::to($receiver)->from("myconfiguredSTMPemail@mycompany.com")->send(new email());

I do this now:

Mail::to($receiver)->from($email_given_by_the_user)->send(new email());

This works fine but I don't like that because I am actually sending them from my e-mail, not from the email given by the user, even if the end user sees it as $email_given_by_the_user. I would like to send it as myconfiguredSTMPemail@mycompany.com but when the user wants to reply, it replies to $email_given_by_the_user. Is there any way to do this?

  • 写回答

1条回答 默认 最新

  • dtxooq1020 2017-05-12 11:59
    关注

    In Laravel 5.4 Mailables, the replyTo, subject, cc, bcc and others can be set inside the mailable in the build method. This is also true for the to which can also be set on the Mail facade.

    So you can do it somelike this:

    $attributes = ['replyTo' => $email_given_by_the_user];    
    Mail::to($receiver)->from("myconfiguredSTMPemail@mycompany.com")->send(new email($attributes));
    

    and email class

    class email extends Mailable
    {
        public $attributes;
    
        public function __construct($attributes = null)
        {
            $this->attributes = $attributes;
        }
    
        public function build()
        {
            if(!empty($this->attributes['replyTo']))
                $this->replyTo($this->attributes['replyTo']);
    
            ...
        }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载