I wanted to make a simple contact form on my Website, where the user get's a confirmation mail and I get the text, the user sent me. But somehow it doesn't work and I don't know why.
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']
]);
}
}
Mail I should get:
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 file:
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
via Sebi