samedi 25 mars 2017

Laravel 5: Error in Sending Email

I am trying to send test emails in my Laravel project, and am encountering the following error:

ErrorException in helpers.php line 532:

htmlspecialchars() expects parameter 1 to be string, object given (View: C:\...\resources\views\mail-test.blade.php)

I've been toying around with my code, following some guidelines/tutorials online the best I can, but I don't see what I'm doing wrong. Code snippets are as follows:

web.php

Route::post('/send-mail', 'MailController@send')->name('send-mail');

sample-page.blade.php

...
<div style="text-align: center;">
   <form action="" method="post">
        
        <input type="email" name="email" placeholder="Email Address">
        <input type="text" name="message" placeholder="Insert Message Here.">
        <button type="submit">Let's send an email!</button>
    </form>
</div>
....

MailController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Mail\Mailer;

use App\Mail\SendMail;

class MailController extends Controller
{
    public function send(Request $request, Mailer $mailer) {
        $mailer
            ->to($request->input('email'))
            ->send(new SendMail($request->input('message')));
        return back();
    }

}

SendMail.php

...
use Queueable, SerializesModels;

public $message;

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct($message)
{
    $this->message = $message;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->from('test@test.com')
                ->view('mail-test');
}

mail-test.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>Email Test</title>
</head>
<body>
    <h1>EMAIL TESTING</h1>
    <p></p>
</body>
</html>



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2ohBs69
via IFTTT

Aucun commentaire:

Enregistrer un commentaire