我想在我的网站上创建一个简单的联系表格,用户会收到确认邮件,我会收到用户发送给我的文本。但不知怎的,它不起作用,我不知道为什么。
ContactController:
public function sendMail(Request $request){
$this->validate($request, [
'email' => 'required|email',
'name' => 'required',
'subject' => 'required',
'text' => 'min:10 | max:65536'
]);
$data = [
'email' => $request->input('email'),
'name' => $request->input('name'),
'subject' => $request->input('subject'),
'text' => $request->input('text')
];
Mail::to($request->input('email'))->send(new RequestReceived($data));
Mail::to('test@velocityvideogroup.com')->send(new ContactEmail($data));
$request->session()->flash('success', 'Request has been successfully sent!');
return redirect('/contact');
}
}
MailClasses:
ConfirmationMail:
class RequestReceived extends Mailable{
use Queueable, SerializesModels;
protected $data;
/**
* Create a new message instance.
*
* @return void-
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.received')
->subject('Velocity | Request received!')
->with([
'name' => $this->data['name'],
'text' => $this->data['text']
]);
}
}
邮件我应该得到:
class ContactEmail extends Mailable
{
use Queueable, SerializesModels;
protected $data;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->markdown('emails.contactemail')
->from($this->data['email'])
->subject($this->data['subject'])
->with([
'name' => $this->data['name'],
'text' => $this->data['text']
]);
}
}
.env
档案:
MAIL_DRIVER=smtp
MAIL_HOST=send.one.com
MAIL_PORT=465
MAIL_USERNAME=test@velocityvideogroup.com
MAIL_PASSWORD=*************
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=test@velocityvideogroup.com
MAIL_FROM_Name=Test