I am beginner in Laravel. I use Laravel 5.8 in my project. I want send email from 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');
$message = "Masz wiadomość ze strony". env('APP_NAME')."<br/>
<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::send('emails.welcome', $message, function ($message) {
//$message->from('us@example.com', 'Laravel');
$message->to($adminEmail, $name = null);
$message->from($email, $name = null);
$message->sender($email, $name = null);
$message->replyTo($adminEmail, $name = null);
$message->subject($title);
//$message->attach($pathToFile, array $options = []);
//$message->attachData($data, $name, array $options = []);
$message->getSwiftMessage();
});
}
$adminEmail - this is my email
How can I send this message as email?
I have error: Argument 2 passed to Illuminate\Mail\Mailer::send() must be of the type array, string given, called in /var/www/vanessa/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 237
How can I repeir it?
In order to send email, you may need to add something like the code snippet mentioned below:
For detailed information on how to send mail please refer this link.
use Illuminate\Support\Facades\Mail;
examples:
hope this helps