Reputation: 1386
I am trying to send a mail using my laravel controller, a very simple mail which is sent in my localhost with no problems but once in server I get this error :
20170325T153701: /public/index.php
PHP Fatal error: Call to a member function send() on a non-object in /public/index.php on line 56
PHP Fatal error: Call to a member function send() on a non-object in /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 107
The browser only shows a 500 error, the error is only seen in my error log. Here is the code used to send the mail
use Illuminate\Support\Facades\Mail; // just to say I'm calling it
$v_code = str_random(30);
$mail_content = array('code' => $v_code);
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['pass']),
]);
if ($user) {
Mail::send('User::mail.verifyMail', $mail_content, function ($message) use ($data) {
$message->to($data['email'], $data['name'])
->subject('Verify your email address');
});
Upvotes: 1
Views: 8992
Reputation: 1386
The solution was on casting the $name with a (string). I don't know why, but anytime the name contains a space (' ') it simply fails and the $name is considered as null. Thus, a (string) resolved this.
Upvotes: 1
Reputation: 530
Remove that use
line.
\Mail::send('User::mail.verifyMail', $mail_content, function ($message) use ($data) {
$message->to($data['email'], $data['name'])
->subject('Verify your email address');
});
Upvotes: 0