[英]How to get the email senders name from the contact form - Laravel Mail
How can i change the Mail Subject, Title and the senders name from the form input fields,如何从表单输入字段更改邮件主题、标题和发件人姓名,
Here's my contact form这是我的联系表格
<h1>Contact</h1>
<form action="contact/store" method="post">
@csrf
<label>Name</label>
<input type="text" name="name" placeholder="Name">
<br>
<label>Email</label>
<input type="email" name="email" placeholder="Email">
<br>
<label>Message</label>
<textarea name="message" cols="30" rows="10"></textarea>
<button type="submit">Submit</button>
</form>
Here's my Mail controller这是我的邮件 controller
public function store(Request $request)
{
$name = $request->name;
$email = $request->email;
$textmessage = $request->message;
$data = array('name' => $name, 'email' => $email, 'textmessage' => $textmessage);
Mail::send('mail', $data, function ($message) {
$message->to('jareerzeenam.29@gmail.com', 'Email Title')->subject('Test Subject 2');
$message->from('test@gmail.com', 'Test Name 2');
});
echo "HTML Email Sent. Check your inbox.";
}
Here's my mail.blade.php这是我的 mail.blade.php
<h1>Hi, i'm {{ $name }}</h1>
<p>Email :{{ $email }}</p>
<p>Message : {{ $textmessage }}</p>
Here's how i get the email as这是我如何获得 email 为
How can i get the name from the contact form input field to my email instead of the static name i have given in the controller, hope my question is understandable.如何从联系表单输入字段中获取名称到我的 email 而不是我在 controller 中给出的 static 名称,希望我的问题可以理解。
Instead of using而不是使用
->to('jareerzeenam.29@gmail.com', 'Email Title')
use利用
->to([['mail' => 'jareerzeenam.29@gmail.com', 'name' => 'Email Title']])
So, to() accepts array of receivers, and a receiver can be an array with name and mail.因此, to() 接受接收者数组,接收者可以是包含名称和邮件的数组。
You just need to assign name
and email
, I didn't find subject, so I left it as default.您只需要指定
name
和email
,我没有找到主题,所以我将其保留为默认值。
Try this:尝试这个:
public function store(Request $request)
{
$name = $request->name;
$email = $request->email;
$textmessage = $request->message;
$data = array('name' => $name, 'email' => $email, 'textmessage' => $textmessage);
Mail::send('mail', $data, function ($message) use ($name, $email) {
$message->to('jareerzeenam.29@gmail.com', 'Email Title')->subject('Test Subject 2');
$message->from($email, $name);
});
echo "HTML Email Sent. Check your inbox.";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.