I am beginner in Laravel. I create function for contact form.
I have this code:
public function sendContactForm($request)
{
$this->validate($request, [
'name' => 'required|string',
'topic' => 'required|string',
'email' => 'required|email',
'message' => 'required|string',
'captcha' => 'required|captcha',
'acceptReg' => 'required|integer',
]);
$adminEmail = $this->frontendRepository->getSystemAdminEmail();
$title = $request->input('topic');
$txt = nl2br($request->input('message'));
$userName = $request->input('name');
$email = $request->input('email');
$ip = $request->getClientIp();
$dateTime = date('Y-m-d H:i:s');
$mailTitle = "Masz wiadomość ze strony". env('APP_NAME')."<br/>";
$message = "
<b>Dane wiadomości:</b> $dateTime [$ip]<br/>
<b>Tytuł wiadomości:</b> $title<br/>
<b>Imię:</b> $userName<br/>
<b>Adres email:</b> $email<br/>
<b>Wiadomość:</b> $txt<br/>";
Mail::to($adminEmail)->send(new ContactMail($message, $mailTitle, $email, $adminEmail));
die('mail sent!');
}
ContactMail.php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class ContactMail extends Mailable
{
use Queueable, SerializesModels;
public $message;
public $title;
public $sender;
public $adminMail;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct(string $message, string $title, string $sender, string $adminMail)
{
$this->message = $message;
$this->title = $title;
$this->sender = $sender;
$this->adminMail = $adminMail;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
//return $this->view('mail.contactform', ['message' => $this->message]);
return $this->subject($this->title)
->from($this->sender)
->to($this->adminMail)
->replyTo($this->sender)
->view('mail.contactform')->send($this->adminMail);
}
When I run my script I have error:
Argument 1 passed to
Illuminate\Mail\Mailable::send()
must implement interface Illuminate\Contracts\Mail\Mailer, string given, called in /var/www/vanessa/app/Mail/ContactMail.php on line 43
How can I repair it?
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2MvCUml
via IFTTT
Aucun commentaire:
Enregistrer un commentaire