![](/img/trans.png)
[英]Incorrect sender email address shows in the mail send using smtp phpmailer
[英]How to send an email in Laravel using the mail class? Can't get the sender email address
我正在创建一个联系表单,我想从request()
中检索发件人 email 地址,但是当我填写联系表单并发送时遇到了一些问题,email 没有出现在 mailtrap 中,所有配置都正确。 我通过执行Mail::to('test@test.com')->send(new ContactFormMail($data));
向收件人发送 email 以使其工作但我想获得发件人 email 地址。
我尝试这样做,但没有发生任何错误或产生了 email,并且数据在数组中正确输出。 所以我有点困惑。
public function store(){
$data = request()->validate([
'name' => 'required',
'email' => 'required|email',
'number' => 'sometimes|nullable',
'message' => 'required',
]);
Mail::send(new ContactFormMail($data), ['data' => $data],
function ($message) use ($data)
{
$message
->from($data['email'])
->to('test@test.com');
});
return redirect('contact-us')->with('message', 'Thanks for your message. We\'ll be in touch.');
}
尝试:
public function build()
{
return $this->from($this->data['email'])
->view('emails.your-email-view');
}
https://laravel.com/docs/7.x/mail#configuring-the-sender
我希望这有帮助。
更新:由于您No hint path defined for [mail]
,因此问题一定是这是 markdown 并且您必须调用->markdown('path-to-template')
,而不是->view
。
这是关于 stackoverflow 的一个常见问题: No hint path defined for [mail] Laravel 5.4
这是我用来检索发件人 email 的解决方案。 Mail::send('Frontend::emails.contact.contact-form', ['data' => $data], function ($message) use ($data) { $message ->from($data['email']) ->to('test@test.com'); });
然而,这导致了另一个问题没有为 [mail] 定义提示路径。 This issue is to do with @component('mail::message') in the email blade so remove this and change the email blade to html which you can copy from the html source in mailtrap. 基本上将 markdown 视为 HTML,因为它试图引用 markdown class。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.