0

am new to laravel, am trying to send a mail to users if they register successfully and in the email it will contain some details

I my app was creating a new account or the new users but the email wasn't sending, it was displaying this error in the network tab

message:    htmlspecialchars() expects parameter 1 to be string, object given (View: C:\xampp\htdocs\laravel Projects\bank\iscbank\resources\views\emails\welcome.blade.php)

here is my code or sending the email

$datty = array(
            'name' => $request->input('name'), 
            'email' => $request->input('email'), 
            'Authenticationkey' => $this->genAutKey, 
            'password' => $this->genPass,
            'AccountNumber' => $this->AccNum,
        );      
        // Mail::to($request->input('email'))->send(new WelcomeMail($datty));

        Mail::send('emails.welcome', ['datty'=>$datty], function ($message) use($datty){
            $message->from(Auth::user()->email, Auth::user()->name);    
            $message->to(Input::get('email'))->subject(Input::get('subject')); 
        });

Here is my Welcomemail.php code

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue; 

class WelcomeMail extends Mailable{
    use Queueable, SerializesModels;
    public $datty;

    public function __construct($datty){
        $this->datty = $datty;
    }

    public function build(){
        return $this->view('emails.welcome');
    }
}

here is my welcome.blade.php code

<div style="background-color: #eeeeef; padding: 50px 0; ">     
<div style="max-width:640px; margin:0 auto; ">        
    <div style="color: #fff; text-align: center; background-color:#33333e; padding: 30px; border-top-left-radius: 3px; border-top-right-radius: 3px; margin: 0;">            
        <h1>Your account details</h1>        
    </div>        
    <div style="padding: 20px; background-color: rgb(255, 255, 255);">            
        <p style="color: rgb(85, 85, 85); font-size: 14px;"> 
            Hello {{ $datty['name']}},<br>
            <br>An account has been created successfully.
        </p>            
        <p style="color: rgb(85, 85, 85); font-size: 14px;"> 
            Please use the following info to login your account: 
        </p>            
        <hr>           
        <p style="color: rgb(85, 85, 85); font-size: 14px;"></p>            
        <p >
            <span style="color: rgb(85, 85, 85); font-size: 14px; line-height: 20px;">
                Email: {{ $datty['email'] }}
            </span><br>
        </p>            
        <p>
            <span style="color: rgb(85, 85, 85); font-size: 14px; line-height: 20px;">
                Password:&nbsp;{{ $datty['password'] }}
            </span>
        </p>          
        <p>
            <span style="color: rgb(85, 85, 85); font-size: 14px; line-height: 20px;">
                Activation Key:&nbsp;{{$datty['Authenticationkey']}}
            </span>
        </p>            
        <p style="color: rgb(85, 85, 85);"><br></p>            
        <p style="color: rgb(85, 85, 85); font-size: 14px;">Thanks</p>        
    </div>    
</div>

pls how can i solve this problem, i tried searching online but they are all saying the samething, pls

  • 1
    One of your variables being used is an object and not a string. A simple var_dump() will you which one. – John Conde Apr 13 '19 at 18:14
  • how can i do that –  Apr 13 '19 at 18:20
  • Did you go to php.net to see how to use that function? – John Conde Apr 13 '19 at 18:20
  • When you get an answer to a question you have to mark it as completed or resolved instead of deleting it. @EloikeDavid – Muhammad Shareyar Apr 13 '19 at 18:39
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – miken32 Apr 13 '19 at 21:36
  • My guess is it is the $datty[‘Authernticationkey’] as the issue is with a variable in your email blade file, and the other two are inputs - check your genAutoKey method that you are calling on Authentication key by typing dd($dutty[‘Authenticationkey’]) after your $dutty variable - then if you haven’t got testing I would assign a ‘test’ route to trigger the controller - check what is being stored for each variable in $dutty – CodeBoyCode Apr 14 '19 at 07:56

0 Answers0